AEInstallEventHandler handler not being called on startup
这是我的Info.pList协议注册:
... <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLname</key> <string>My Protocol</string> <key>CFBundleURliconfile</key> <string>myicon</string> <key>CFBundleTypeRole</key> <string>VIEwer</string> <key>CFBundleURLSchemes</key> <array> <string>myapp</string> </array> </dict> </array>
这里是我设置方法来监听kInternetEventClass / kAEGetURL事件,当浏览器链接点击链接“myapp:// unused /?a = 123& b = 456”时:
- (voID)applicationDIDFinishLaunching:(NSNotification *)notification{ [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(getURL:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; ...}
这是处理方法:
- (voID)getURL:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)reply{ [[[event paramDescriptorForKeyword:keyDirectObject] stringValue] writetofile:@"/testbed/complete_url.txt" atomically:YES];}
这是测试网络链接:
<!DOCTYPE HTML PUBliC "-//W3C//DTD HTML 4.01//EN"><HTML lang="en"><head></head><body> <a href="myapp://open/?a=123&b=456">Open My App</a></body></HTML>
如果应用程序已经运行,这一切都会很好.
调用处理程序方法,并捕获完整的URL.
然而,如果应用程序尚未运行,则将启动该应用程序,但不会调用该处理程序 – 这是有道理的,因为该处理程序尚未绑定到该事件.
URL中的这些参数对于我们的应用程序与webapp协调是很重要的.虽然绝大多数时间我们的应用程序将在此次点击发生时已经运行,但有时候可以期待它不会.
我已经尝试检查环境和处理调用参数,我没有看到任何一个的URL.
任何人都知道如何可靠地捕获此URL,即使当浏览器点击发生时,我们的应用程序尚未运行?
解决方法 Apple的SimpleScriptingPlugin示例在applicationWillFinishLaunching:中注册处理程序,这可能比使用init更干净. (和mikker说的一样,处理程序在applicationDIDFinishLaunching之前被调用:) 总结以上是内存溢出为你收集整理的objective-c – 使用NSAppleEventManager和kInternetEventClass / kAEGetURL的Cocoa协议处理程序全部内容,希望文章能够帮你解决objective-c – 使用NSAppleEventManager和kInternetEventClass / kAEGetURL的Cocoa协议处理程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)