是否可以在不添加 UIApplicationDelegate 回调的情况下接收 URL 数据?
我正在编写一个共享管理器类。它知道通过侦听 UIApplicationDidBecomeActiveNotification 等来启动和停止某些服务。它还应该做的是处理一组特定的 URL。目前,我通过向每个应用程序中的 UIApplicationDelegate 添加代码来实现这一点,如下所示:
#pragma mark - URL support
// Pre 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [[SGBMyManager sharedManager] handleOpenURL:url];
}
// For 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [[SGBMyManager sharedManager] handleOpenURL:url];
}
这可行,但不是很干。我只想在我的共享管理器类中编写一次代码。是否有我可以监听的 UIApplicationDidHandleOpenURL
通知或类似通知?
I'm writing a shared manager class. It knows to start and stop some services by listening for the UIApplicationDidBecomeActiveNotification
and similar. It's also supposed to do is to handle a certain set of URLs. At the moment, I'm getting it to do that by adding code to the UIApplicationDelegate in each of our apps like so:
#pragma mark - URL support
// Pre 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [[SGBMyManager sharedManager] handleOpenURL:url];
}
// For 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [[SGBMyManager sharedManager] handleOpenURL:url];
}
That works, but it's not very DRY. I'd like to only have to code this once, in my shared manager class. Is there a UIApplicationDidHandleOpenURL
notification or similar that I could listen for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论