如果应用程序从后台清除,如何处理本地通知

How to handle local notification if the app is cleared from background

我刚刚创建了一个应用程序来通知特定的任务time.And它非常准时。 如果我点击通知栏,它会打开应用程序并显示一个警告框。

但是当我从后台清除应用程序时出现问题。通知有效,但通过通知打开应用程序时我看不到警告框。

有知道的请帮忙

试试这个:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

    if(userInfo)
    {

        [self application:application didReceiveRemoteNotification:userInfo];


    }

    return YES;
}
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
}

swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        if let lanuchOptions = launchOptions,
            let userInfo = lanuchOptions[UIApplicationLaunchOptionsKey.remoteNotification] as? [AnyHashable: Any] {

            self.application(application, didReceiveRemoteNotification: userInfo)
        }

        return true
    }

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {

}