应用启动后能否获得iOS启动通知? [英] Can I get the iOS Startup Notification after the application has started?

查看:91
本文介绍了应用启动后能否获得iOS启动通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在iOS上检索UIApplicationLaunchOptionsLocalNotificationKey的方法,该方法不涉及使用应用程序委托,即,我不想实现以下内容:

I'm looking for a way to retrieve the UIApplicationLaunchOptionsLocalNotificationKey on iOS that doesn't involve using the application delegate, i.e. I don't want to have to implement the following:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UILocalNotification *localNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsLocalNotificationKey];
    if (localNotification != nil)
    {
        // Process notification
    }
}

我正在尝试创建一个需要有关启动通知信息的帮助程序库.反正有这样做吗?我可以在申请过程的稍后阶段通过另一种方法检索启动选项吗?

I'm trying to create a helper library that needs information about the startup notification. Is there anyway of doing this? Can I retrieve the launch options via another method at a later point in the application process?

推荐答案

您可以将自己添加为 UIApplicationDidFinishLaunchingNotification 通知的观察者,该通知将由应用程序提出并包含您要查找的信息

You can add yourself as an observer of the UIApplicationDidFinishLaunchingNotification notification which will be posed by the application and contains the information you are looking for.

正如@Stavash所建议的那样,存在局限性.对于第一次启动,您将无法接收此通知,因为将不会创建库的实例(您的类必须位于根XIB中).但是,当重新打开应用程序以进行本地/远程通知时,也会发送此通知.

As @Stavash suggests, there are limitations. For the first launch you won't be able to pick this notification up because the instance of your library won't be created (your class would need to be in the root XIB). But, this notification will also be sent when the app is re-opened for local / remote notifications.

这篇关于应用启动后能否获得iOS启动通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆