iphone Launch Options

后端 未结 6 1091
刺人心
刺人心 2020-12-17 00:38

im not getting any launch options after a push notification; heres the code i have but non of the NSLogs seem to print in the debug area.

UILocalNotification         


        
相关标签:
6条回答
  • 2020-12-17 00:43

    The answers given above are correct. I largely use the following snippet in my application:didFinishLaunchingWithOptions:

    if let remoteNotifPayload = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [AnyHashable: Any] {
            notificationsController.didReceiveRemoteNotification(with: remoteNotifPayload)
        }
    
    0 讨论(0)
  • You can use NSUserDefaults to do the trick. In your AppDeligate.m, set a bool to YES in the first time. So after that it never gets to NO.

      -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        //add this if loop
            if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
            {
                [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
                [[NSUserDefaults standardUserDefaults] synchronize];
            }
        }
    
    0 讨论(0)
  • 2020-12-17 00:48
      (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
          NSLog(@"Alert message: %@",[[userInfo valueForKey:@"aps"] valueForKey:@"alert"]);
    }
    
    0 讨论(0)
  • 2020-12-17 00:49

    If you want a local notification (I assume with your var name) replace UIApplicationLaunchOptionsRemoteNotificationKey by UIApplicationLaunchOptionsLocalNotificationKey and this should work.

    0 讨论(0)
  • 2020-12-17 00:54

    Your application receives push notifications through multiple paths, depending on the state of your app when it is received.

    If your app is not launched (not even suspended in background), the launchOptions will contain the notification payload (key UIApplicationLaunchOptionsRemoteNotificationKey).

    If it is already running or suspended in background, the app will receive the notifications via application:didReceiveRemoteNotification: in your application delegate.

    The process is the same for local notifications (UIApplicationLaunchOptionsLocalNotificationKey in application:didFinishLaunchingWithOptions: and application:didReceiveLocalNotification:)

    0 讨论(0)
  • 2020-12-17 00:55

    an error spotted:

    NSDictionary *remoteNotif = [launchOptions objectForKey:   
                                  UIApplicationLaunchOptionsRemoteNotificationKey];
    

    If you want to receive the remote notification, NSDictionary should be used not UILocalNotification

    The remote notification is a payload, containing arguments, not a local notification. You might want to look at this url question:

    Crash when handling remote notification when app not running

    If you want to do local notification, change it like Ludovic's suggestion

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