关于友盟分享成功以后,点击"留在QQ","留在微信"...无法判断分享是否成功问题

如果分享成功以后,点击“留在QQ”,"留在微信"...
就不会调用下面的方法:

-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options{}
就无法判断分享是否成功,也无法进行分享成功你想进行的操作(例如:分享成功获取积分,奖励等。。。)


如果点击“返回XXX”,方法的调用顺序如下:

1:界面即将进入前台

- (void)applicationWillEnterForeground:(UIApplication *)application
2:分享结果回调
-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
3:界面已经进入活跃状态(前台)
- (void)applicationDidBecomeActive:(UIApplication *)application


如果点击“留在QQ”,方法的调用顺序如下:

1:即将进入前台

- (void)applicationWillEnterForeground:(UIApplication *)application 
2:界面已经进入前台
- (void)applicationDidBecomeActive:(UIApplication *)application


解决方法:

1.在点击QQ,微信分享的时候,设置一个全局的标识:(根据自己的需要,设置不同的变量)

NSUserDefaults * userDef = [NSUserDefaults standardUserDefaults];
[userDef setBool:YES forKey:@"IS_SHARE"];//标记是否点击
[userDef synchronize];
2.在分享结果回调的方法中实现:

-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options{
    BOOL result = [UMSocialSnsService handleOpenURL:url];
    NSString * urlString = [url absoluteString];
    NSLog(@"%@",urlString);
    if([urlString hasPrefix:@"QQ"]){
        //QQ
        if (![urlString containsString:@"error=0"]) {//QQ分享成功会有error=0字段
            NSUserDefaults * userDef = [NSUserDefaults standardUserDefaults];
            [userDef setBool:NO forKey:@"IS_SHARE"];
            [userDef synchronize];
        }
    }
    return result;
}
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response{
    NSLog(@"分享结果:%@",response);
    if (response.responseCode != 200) {
        NSUserDefaults * userDef = [NSUserDefaults standardUserDefaults];
        [userDef setBool:NO forKey:@"IS_SHARE"];
        [userDef synchronize];
    }
}


 
   3.在已经进入页面以后: 
   

- (void)applicationDidBecomeActive:(UIApplication *)application {
    NSUserDefaults * userDef = [NSUserDefaults standardUserDefaults];
    BOOL isShare = [userDef boolForKey:@"IS_SHARE"];
    if (isShare) {
        //进行自己想要做的操作,增加用户积分,发放奖励等。。。。
    }
}








你可能感兴趣的:(iOS开发,友盟分享成功无回调,点击留在QQ,分享成功以后获取积分)