这是代码工作正常,以便通过实现 NSServices 从另一个任何其他应用程序接收和返回一个 NSString,如下所述:https ://developer.apple.com/library/mac/documentation/cocoa/conceptual /SysServices/Articles/properties.html
- (void)simpleEncrypt:(NSPasteboard *)pboard
userData:(NSString *)userData error:(NSString **)error {
// Test for strings on the pasteboard.
NSArray *classes = [NSArray arrayWithObject:[NSString class]];
NSDictionary *options = [NSDictionary dictionary];
if (![pboard canReadObjectForClasses:classes options:options]) {
*error = NSLocalizedString(@"Error: couldn't encrypt text.",
@"pboard couldn't give string.");
return;
}
// Get and encrypt the string.
NSString *pboardString = [pboard stringForType:NSPasteboardTypeString];
NSString *newString = [self rotateLettersInString:pboardString];
if (!newString) {
*error = NSLocalizedString(@"Error: couldn't encrypt text.",
@"self couldn't rotate letters.");
return;
}
// Write the encrypted string onto the pasteboard.
[pboard clearContents];
[pboard writeObjects:[NSArray arrayWithObject:newString]];
}
有没有办法获取发件人应用程序具有所选文本的位置、位置和/或坐标,以便在该位置准确显示弹出窗口?