• ios UIApplocation 中APP启动方式


    iOS app启动的方式有哪些:

    1. 自己启动(用户手动点击启动)
    2. urlscheme启动(关于urlScheme的详解)http://www.cnblogs.com/sunfuyou/p/6183064.html
    3. 本地通知启动  (自己写的本地通知启动,蓝牙模块的启动,地理围栏的启动)
    4. 远程通知启动    (后台服务器的推送通知

    //APPdelegate.m中写上这个方法

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

     //系统中自带的launchoption的字典里面的所有key

    UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsURLKey                   NS_AVAILABLE_IOS(3_0); // userInfo contains NSURL with launch URL

    UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsSourceApplicationKey     NS_AVAILABLE_IOS(3_0); // userInfo contains NSString with launch app bundle ID

    UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsRemoteNotificationKey    NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED; // userInfo contains NSDictionary with payload

    UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsLocalNotificationKey     NS_AVAILABLE_IOS(4_0) __TVOS_PROHIBITED; // userInfo contains a UILocalNotification

    UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsAnnotationKey            NS_AVAILABLE_IOS(3_2); // userInfo contains object with annotation property list

    UIKIT_EXTERN NSString *const UIApplicationProtectedDataWillBecomeUnavailable    NS_AVAILABLE_IOS(4_0);

    UIKIT_EXTERN NSString *const UIApplicationProtectedDataDidBecomeAvailable       NS_AVAILABLE_IOS(4_0);

    UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsLocationKey              NS_AVAILABLE_IOS(4_0); // app was launched in response to a CoreLocation event.

    UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsNewsstandDownloadsKey    NS_AVAILABLE_IOS(5_0) __TVOS_PROHIBITED; // userInfo contains an NSArray of NKAssetDownload identifiers

    UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsBluetoothCentralsKey     NS_AVAILABLE_IOS(7_0); // userInfo contains an NSArray of CBCentralManager restore identifiers

    UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsBluetoothPeripheralsKey  NS_AVAILABLE_IOS(7_0); // userInfo contains an NSArray of CBPeripheralManager restore identifiers

    UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsShortcutItemKey          NS_AVAILABLE_IOS(9_0) __TVOS_PROHIBITED; // userInfo contains the UIApplicationShortcutItem used to launch the app.

     // Key in options dict passed to application[will | did]FinishLaunchingWithOptions and info for UIApplicationDidFinishLaunchingNotification  

    UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsUserActivityDictionaryKey    NS_AVAILABLE_IOS(8_0); // Sub-Dictionary present in launch options when user activity is present

    UIKIT_EXTERN NSString *const UIApplicationLaunchOptionsUserActivityTypeKey          NS_AVAILABLE_IOS(8_0); // Key in user activity dictionary for the activity type

    判断启动代码如下:

     

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

      // Override point for customization after application launch.  

      //用户自己点击启动  

      if(!launchOptions)  

          {  

              NSLog(@"用户点击app启动");  

        }  else      {  

        NSURL *url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];  

        //app 通过urlscheme启动  

        if (url) {  

                  NSLog(@"app 通过urlscheme启动 url = %@",url);  

              }  

        UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];  

        //通过本地通知启动  

        if(localNotification)  

              {  

                  NSLog(@"app 通过本地通知启动 localNotification = %@",localNotification);  

              }  

        NSDictionary *remoteCotificationDic = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];  

        //远程通知启动  

        if(remoteCotificationDic)  

                {  

                  NSLog(@"app 通过远程推送通知启动 remoteCotificationDic = %@",remoteCotificationDic);  

              }  

          }  

      return YES;  

    }  

    //位置变动的通知  

            if(launchOptions[@"UIApplicationLaunchOptionsLocationKey"])  

            {  

          //写你的重新定位的代码  

            }  


    总结:当launchOptions为空时是用户自己点击app启动,不为空时,要根据相应的key是否存在来判断是通过哪种方式启动的。

  • 相关阅读:
    JSON解析之——Android
    Xml解析之——Java/Android/Python
    Design Pattern —— Singleton
    设计模式(10)--观察者模式
    设计模式(9)--建造者模式
    设计模式(8)--外观模式
    设计模式(7)--模板模式
    设计模式(6)--原型模式
    设计模式(5)--工厂模式
    设计模式(4)--代理模式
  • 原文地址:https://www.cnblogs.com/sunfuyou/p/6183017.html
Copyright © 2020-2023  润新知