Handling Push Notifications when App is NOT running

后端 未结 8 2181
感动是毒
感动是毒 2020-11-29 16:57

When my App is not running and receives a Push Notification, if I click on that notification, the App is launched - but then it doesn\'t prompt the

8条回答
  •  无人及你
    2020-11-29 17:23

    try this

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
        // Override point for customization after application launch.
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
    
        //register notifications
        if([application respondsToSelector:@selector(registerUserNotificationSettings:)]) // ios 8
        {
            [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
            [application registerForRemoteNotifications];
        }
        else // ios 7
        {
            [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge];
        }
    
        // open app from a notification
        NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    
        if (notification) 
        {
            //your alert should be here
        }
    
        // Set icon badge number to zero
        application.applicationIconBadgeNumber = 0;
    
        return YES;
    }
    

提交回复
热议问题