检查应用是否因RemoteNotification而启用(应用已启动)

时间:2016-11-09 12:06:30

标签: ios swift push

我想区分app appAsctive是否响应RemoteNotification点击。怎么做 ?

1 个答案:

答案 0 :(得分:0)

你可以像这样检查

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
       NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
                if (notification) {

                // it's launch from notification


                }
                else
                {
                     // normal launch on app icon click
                }

    }

对于swift plz使用此

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        if (launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? NSDictionary) != nil {

           // it's launch from notification
                   }
        else
        {
              // normal launch on app icon click 
        }

        // Override point for customization after application launch.
        return true
    }