简体   繁体   中英

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

I just created an application to notify the task in a specific time.And It's working perfectly on time. If I click on the notification bar it opens the app and show a alert box.

But I have problem when i cleared the application from background. Notification is working but I can't able to see the alert box when the application is opens through notification.

Please help if any one know

try this:

- (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]) {

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM