当前位置: 首页 > news >正文

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是否存在来判断是通过哪种方式启动的。

相关文章:

  • 推送知识点2
  • 各种数据库连接字符串
  • Java程序,JDK的安装、环境的配置
  • 写一个简易的shell脚本(二)
  • css中import与link用法区别
  • 避免死锁
  • ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
  • Linux下如何修改Apache根目录
  • Linux at 定时任务
  • 墨香带你学Launcher之(七)--小部件的加载、添加以及大小调节
  • 命令行工具
  • 远程过程调用协议(RPC)
  • Linux命令-自动挂载文件/etc/fstab功能详解[转]
  • maven 子项目 deploy 到私服
  • jQuery拖动剪裁图片作为头像
  • [译] 怎样写一个基础的编译器
  • angular2 简述
  • go append函数以及写入
  • iBatis和MyBatis在使用ResultMap对应关系时的区别
  • mongo索引构建
  • Next.js之基础概念(二)
  • open-falcon 开发笔记(一):从零开始搭建虚拟服务器和监测环境
  • Promise面试题2实现异步串行执行
  • Vim 折腾记
  • 阿里云ubuntu14.04 Nginx反向代理Nodejs
  • 闭包--闭包作用之保存(一)
  • 二维平面内的碰撞检测【一】
  • 解决iview多表头动态更改列元素发生的错误
  • 看到一个关于网页设计的文章分享过来!大家看看!
  • ​DB-Engines 12月数据库排名: PostgreSQL有望获得「2020年度数据库」荣誉?
  • # 安徽锐锋科技IDMS系统简介
  • # 深度解析 Socket 与 WebSocket:原理、区别与应用
  • #LLM入门|Prompt#2.3_对查询任务进行分类|意图分析_Classification
  • #我与Java虚拟机的故事#连载16:打开Java世界大门的钥匙
  • (02)Hive SQL编译成MapReduce任务的过程
  • (delphi11最新学习资料) Object Pascal 学习笔记---第2章第五节(日期和时间)
  • (附源码)spring boot公选课在线选课系统 毕业设计 142011
  • (算法)求1到1亿间的质数或素数
  • (提供数据集下载)基于大语言模型LangChain与ChatGLM3-6B本地知识库调优:数据集优化、参数调整、Prompt提示词优化实战
  • (原創) 系統分析和系統設計有什麼差別? (OO)
  • .bat批处理(十):从路径字符串中截取盘符、文件名、后缀名等信息
  • .equals()到底是什么意思?
  • .net 8 发布了,试下微软最近强推的MAUI
  • .NET/C# 在 64 位进程中读取 32 位进程重定向后的注册表
  • .secret勒索病毒数据恢复|金蝶、用友、管家婆、OA、速达、ERP等软件数据库恢复
  • .set 数据导入matlab,设置变量导入选项 - MATLAB setvaropts - MathWorks 中国
  • [ C++ ] 继承
  • [ SNOI 2013 ] Quare
  • [] 与 [[]], -gt 与 > 的比较
  • [2]十道算法题【Java实现】
  • [AutoSar]BSW_Memory_Stack_004 创建一个简单NV block并调试
  • [C++]类和对象(中)
  • [CISCN 2023 初赛]go_session
  • [ERROR] Plugin 'InnoDB' init function returned error
  • [Flutter]WindowsPlatform上运行遇到的问题总结