How to open an ios Application on Tap of Push Noti

2019-05-11 22:59发布

问题:

May i know, how to open an ios application, on tapping on notification. Or when we swipe an icon (in case when iphone is locked.) of notification?

Can anyone please help me out here?

回答1:

The OS handles the behavior when tapping the notification as it comes in. Doesn't matter if it is sent by a 3rd party or not, if it is going through APNS, it will open the application and inside applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if (launchOptions != nil) {
         // Launched from push notification
         NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    }
}

If the app happens to be already open when the notification comes in the OS will fire the delegate method:

 - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary *)userInfo {   
     // Do something
}


回答2:

It's automatically open the app. Apple do the stuff for us. We don't need to code anything for open the app.



回答3:

The app is opened automatically, but the last view controller you were in. So in order to open you desired view controller just implement application:didReceiveRemoteNotification: Further explanation here.



回答4:

On pressing the local notification, app launches automatically.