我试图让我的程序提供查找单词的服务。当我将一些文本拖到图标上时它可以工作,但是当我尝试使用菜单项时,它会打开应用程序的另一个实例,冻结我发送请求的应用程序大约 30 秒,然后不执行它应该执行的方法至。
这是我的方法:
- (void)serviceQuery:(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;
}
NSString *baseURL = @"http://labs.valtyrorn.com/bin/leit.php?q=";
NSString *q = [pboard stringForType:NSPasteboardTypeString];
NSString * encoded = [q stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *query = [NSString stringWithFormat:@"%@%@", baseURL, encoded];
[webView setMainFrameURL:query];
NSLog(query);
}
plist 的服务部分如下所示:
<key>NSServices</key>
<array>
<dict>
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
</array>
<key>NSMessage</key>
<string>serviceQuery</string>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Fáðu beygingarlýsingu</string>
</dict>
<key>NSPortName</key>
<string>BIN</string>
<key>NSRequiredContext</key>
<dict></dict>
</dict>
</array>
有谁知道如何解决这一问题?