ios 应用启动方式判断

2017-05-03  本文已影响67人  idream

// 启动类型的枚举变量

typedef NS_ENUM(NSUInteger, STARTUP_TPYE)

{

STARTUP_TPYE_BY_NOMAL = 0,

STARTUP_TPYE_BY_NOTIFICATION,

STARTUP_TPYE_BY_PUSH,

STARTUP_TPYE_BY_SCHEME,

};

- (STARTUP_TPYE)checkStartUpType:(NSDictionary *)launchOptions

{

STARTUP_TPYE startType = STARTUP_TPYE_BY_NOMAL;

if (launchOptions) {

// 有远程通知

NSDictionary *payload = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

if (payload) {

startType =  STARTUP_TPYE_BY_PUSH;

}

// 有本地通知

UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];

if (localNotification) {

startType =  STARTUP_TPYE_BY_NOTIFICATION;

}

// 有第三方APP调用

NSURL* launchURL = (NSURL*)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];

if(launchURL) {

startType =  STARTUP_TPYE_BY_SCHEME;

}

} else {

startType = STARTUP_TPYE_BY_NOMAL;

}

return startType;

}

上一篇下一篇

猜你喜欢

热点阅读