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

后端 未结 4 1084
遇见更好的自我
遇见更好的自我 2021-01-16 05:41

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

相关标签:
4条回答
  • 2021-01-16 05:50

    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");
        }
    
    0 讨论(0)
  • 2021-01-16 05:52

    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

    enter image description here

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

    enter image description here

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

    enter image description here

    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

    0 讨论(0)
  • 2021-01-16 06:06

    Below method is invoked when a remote notification is received in iOS.

    func application(_ application: UIApplication,
                     didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // do something
    }
    

    Apart from basic setup for remote notifications you should set below flag in payload of notification.

    "content-available": 1
    
    0 讨论(0)
  • 2021-01-16 06:12

    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

    0 讨论(0)
提交回复
热议问题