【iOS】app启动入口

2016-07-19  本文已影响966人  24c41111e47b
启动原因
应用方法

支付宝外部应用跳转处理
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {
/

如:跳转支付宝app支付时,app被kill,支付完成后,从支付宝app跳转回app(即重新启动),
return NO 不调用application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options,
直接返回首页
*/
if (launchOptions) {
NSString *appIDF = [launchOptions objectForKey:UIApplicationLaunchOptionsSourceApplicationKey];
if (appIDF && [appIDF isEqualToString:@"com.alipay.iphoneclient"]) {
return NO;
//return YES;//需要处理返回的URL返回YES
}
return YES;
}
当程序入口函数返回YES时调用下面方法:

-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {

NSString *urlStr = [urlabsoluteString];
// 支付宝app进app
if(sourceApplication && [sourceApplication isEqualToString:@"com.alipay.iphoneclient"]){
    [[AlipaySDK defaultService] processOrderWithPaymentResult:urlstandbyCallback:^(NSDictionary *resultDic) {
        NSDictionary *dict = @{ALIPayDidCompleteURLKey:urlStr};
        [[NSNotificationCenter defaultCenter] postNotificationName:ALIPayFromZFBDidCompleteNotification object:resultDic userInfo:dict];
    }];
}
returnYES;

}

在支付类初始化方法中:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(processAliPayResult:) 
                                        name:ALIPayFromZFBDidCompleteNotification object:nil];
上一篇下一篇

猜你喜欢

热点阅读