Search code examples
iosobjective-cuilocalnotification

Do not open the app when a local notification is clicked in iOS


When I click on a local notification from the notification centre I want to prevent it from opening my application, i.e when the notification is clicked nothing should happen other than just clearing it. Any idea how to do it?


Solution

  • For sure Apple will reject such app.

    But below is what you can do if you want to do such thing, but this will open app.

    In - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {, have below.

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
        //home button press programmatically
        UIApplication *app = [UIApplication sharedApplication];
        [app performSelector:@selector(suspend)];
    
        //exit app when app is in background
        exit(0);
    }
    

    In short, on opening app from push, kill the app.