Which method will be triggered when the notification received on iPhone(not after the notification is tapped and opened)?

雨燕双飞 提交于 2019-12-30 11:41:25

问题


I’m now using didReceiveRemoteNotification to get the payload of the notification pushed from Parse, however, it is only triggered when the notification is tapped and opened.

What I’m trying to do is start an alarm to remind the user that a notification has arrived, so I guess didReceiveRemoteNotification is not what I’m looking for. Which method should I look into for this purpose?

Thank you!


回答1:


Words from The WWDC 2014 Whats New in iOS Notifications

Local and push notifications let background or inactive apps notify users that an event of interest has occurred, or that an app has new information for them.

The WWDC 2013 Whats New With Multitasking tells us how to get this work.

• add UIBackgroundModes : remote-notification in info.plist

• add `content-available: 1 in your Payload while sending from server

• lets iOS handle it to open your app for background mode

For iOS 10 and above you have to switch ON the Background Modes from your Target -> Under Capabilities and check mark the required fields.

Now you can set your alarm as you want. you may set a scheduled local notification until user interact with app




回答2:


You can do nothing with the push notification unless the user taps on the notification banner OR the app is in foreground. In background, you do not have control. Reference Apple Push Notification setting up Remote Notifications method overrides other methods




回答3:


You must look for this method in app delegate:-

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

Now check whether your app has received any push notification/'s or not

UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if (notification) {
        NSLog(@"app received a notification %@",notification);
        [self application:application didReceiveRemoteNotification:(NSDictionary*)notification];
    }else{
        NSLog(@"app did not receive a notification");
    }


来源:https://stackoverflow.com/questions/30257124/which-method-will-be-triggered-when-the-notification-received-on-iphonenot-afte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!