Push Notification -didFinishLaunchingWithOptions

后端 未结 5 1458
[愿得一人]
[愿得一人] 2020-12-05 15:24

When I send a push notification and my app is open or in the background and I click on the push notification, my application redirects to PushMessagesVc v

5条回答
  •  庸人自扰
    2020-12-05 15:56

    Swift 2.0 For 'Not Running' State (Local & Remote Notification)

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
    
    // Handle notification
    if (launchOptions != nil) {
    
        // For local Notification
        if let localNotificationInfo = launchOptions?[UIApplicationLaunchOptionsLocalNotificationKey] as? UILocalNotification {
    
            if let something = localNotificationInfo.userInfo!["yourKey"] as? String {
    
                self.window!.rootViewController = UINavigationController(rootViewController: YourController(yourMember: something))
            }
    
    
        } else
    
        // For remote Notification
        if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as! [NSObject : AnyObject]? {
    
            if let something = remoteNotification["yourKey"] as? String {
                self.window!.rootViewController = UINavigationController(rootViewController: YourController(yourMember: something))
            }
        }
    
    }
    
    
    return true
    

    }

提交回复
热议问题