- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
說明:當應(yīng)用程序啟動時執(zhí)行收恢,應(yīng)用程序啟動入口。只在應(yīng)用程序啟動時執(zhí)行一次。
application參數(shù)用來獲取應(yīng)用程序的狀態(tài)范舀、變量等,值得注意的是字典參數(shù):(NSDictionary *)launchOptions了罪,該參數(shù)存儲程序啟動的原因锭环。
若用戶直接啟動,lauchOptions內(nèi)無數(shù)據(jù);
若由其他應(yīng)用程序通過openURL:啟動泊藕,則UIApplicationLaunchOptionsURLKey對應(yīng)的對象為啟動URL(NSURL),UIApplicationLaunchOptionsSourceApplicationKey對應(yīng)啟動的源應(yīng)用程序的bundle ID (NSString)辅辩;
若由本地通知啟動,則UIApplicationLaunchOptionsLocalNotificationKey對應(yīng)的是為啟動應(yīng)用程序的的本地通知對象(UILocalNotification);
若由遠程通知啟動玫锋,則UIApplicationLaunchOptionsRemoteNotificationKey對應(yīng)的是啟動應(yīng)用程序的的遠程通知信息userInfo(NSDictionary)蛾茉;
其他key還有UIApplicationLaunchOptionsAnnotationKey,UIApplicationLaunchOptionsLocationKey,
UIApplicationLaunchOptionsNewsstandDownloadsKey。 如果要在啟動時景醇,做出一些區(qū)分臀稚,那就需要在下面的代碼做處理。 比如:應(yīng)用可以被某個其它應(yīng)用調(diào)起(作為該應(yīng)用的子應(yīng)用)三痰,要實現(xiàn)單點登錄吧寺,那就需要在啟動代碼的地方做出合理的驗證,并跳過登錄散劫。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ NSURL *url = [launchOptionsobjectForKey:UIApplicationLaunchOptionsURLKey];
if(url) {
}
NSString *bundleId = [launchOptionsobjectForKey:UIApplicationLaunchOptionsSourceApplicationKey];
if(bundleId) {
} UILocalNotification * localNotify = [launchOptionsobjectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if(localNotify) { }
NSDictionary * userInfo = [launchOptionsobjectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if(userInfo) {
}}
應(yīng)用 /**
* 跳轉(zhuǎn)支付寶app支付時稚机,app被kill,支付完成后获搏,從支付寶app跳轉(zhuǎn)app赖条,return NO 不調(diào)用application: openURL:sourceApplication:annotation:(返回app首頁)
*/
if (launchOptions) {
NSString *appIDF = [launchOptionsobjectForKey:UIApplicationLaunchOptionsSourceApplicationKey];
if (appIDF && [appIDFisEqualToString:@"com.alipay.iphoneclient"]) {
returnNO;
}
}
#pragma mark--外部應(yīng)用跳轉(zhuǎn)到app的url處理
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSString *urlStr = [urlabsoluteString];
// 支付寶app進app
if(sourceApplication && [sourceApplicationisEqualToString:@"com.alipay.iphoneclient"]){
[[AlipaySDKdefaultService] processOrderWithPaymentResult:urlstandbyCallback:^(NSDictionary *resultDic) {
NSDictionary *dict = @{ALIPayDidCompleteURLKey:urlStr};
[[NSNotificationCenterdefaultCenter ] postNotificationName:ALIPayFromZFBDidCompleteNotificationobject:resultDic userInfo:dict];
}];
}
returnYES;
}
//在支付類初始化方法
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(processAliPayResult:)name:ALIPayFromZFBDidCompleteNotificationobject:nil];