ios QQ分享

2018-01-23  本文已影响1643人  未完成1307

QQ分享 需要配置的和微信[微信分享]https://www.jianshu.com/p/0225b32c8f1a大同小异 这里 就直接截图了

添加SDK依赖的系统库文件。分别是”Security.framework”, “libiconv.dylib”,“SystemConfiguration.framework”,“CoreGraphics.Framework”、“libsqlite3.dylib”、“CoreTelephony.framework”、“libstdc++.dylib”、“libz.dylib”。


添加依赖库.png
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    //注意: 初始化授权 开发者需要在这里填入自己申请到的 AppID
    _oauth = [[TencentOAuth alloc] initWithAppId:__TencentDemoAppid__ andDelegate:self];
    
    
    return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation


{     NSString *path = [url absoluteString];
    if ([self.qqDelegate respondsToSelector:@selector(shareSuccssWithQQCode:)]) {
        [self.qqDelegate shareSuccssWithQQCode:[[path substringWithRange:NSMakeRange([path rangeOfString:@"&error="].location+[path rangeOfString:@"&error="].length, [path rangeOfString:@"&version"].location-[path rangeOfString:@"&error="].location)] integerValue]];
    }
    return [TencentOAuth HandleOpenURL:url];

}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return [TencentOAuth HandleOpenURL:url];
}

具体实现 (这里只记录了其中一种分享方式 其他的参考文档)
sendReq QQ

  NSURL *url = [NSURL URLWithString:_webModel.url];
            NSURL *preimageUrl = [NSURL URLWithString:_webModel.image];
            QQApiNewsObject* img = [QQApiNewsObject objectWithURL:url title:_webModel.title description:[NSString stringWithFormat:@"%@",_webModel.content] previewImageURL:preimageUrl];
            
            
            SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:img];
            
            appdelegate.qqDelegate = self;
            
            QQApiSendResultCode sent = [QQApiInterface sendReq:req];//分享给QQ好友
            
            [self handleSendResult:sent];

SendReqToQZone QQ空间

 NSURL *url = [NSURL URLWithString:_webModel.url];
            NSURL *preimageUrl = [NSURL URLWithString:_webModel.image];
            QQApiNewsObject* img = [QQApiNewsObject objectWithURL:url title:_webModel.title description:[NSString stringWithFormat:@"%@",_webModel.content] previewImageURL:preimageUrl];
            
            //请求帮助类,分享的所有基础对象,都要封装成这种请求对象。
            SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:img];
            
            //通过自定义的qqdelegate来通知本controller,是否成功分享
            appdelegate.qqDelegate = self;
            
            QQApiSendResultCode sent = [QQApiInterface SendReqToQZone:req];//分享到QQ空间
            
            [self handleSendResult:sent];

回调

- (void)handleSendResult:(QQApiSendResultCode)sendResult
{
    switch (sendResult)
    {
            
        case EQQAPIAPPNOTREGISTED:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"App未注册" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            
            break;
        }
        case EQQAPIMESSAGECONTENTINVALID:
        case EQQAPIMESSAGECONTENTNULL:
        case EQQAPIMESSAGETYPEINVALID:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            
            break;
        }
        case EQQAPIQQNOTINSTALLED:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的设备未安装手机QQ" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            
            break;
        }
        case EQQAPIQQNOTSUPPORTAPI:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的设备未安装手机QQ" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            
            break;
        }
        case EQQAPISENDFAILD:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"发送失败" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            
            
            break;
        }
        case EQQAPIVERSIONNEEDUPDATE:
        {
            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"当前QQ版本太低,需要更新" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [msgbox show];
            break;
        }
        default:
        {
            break;
        }
    }
}

#pragma mark QQ分享回调代理
/* 返回码 对照说明
 0   成功
 -1  参数错误
 -2  该群不在自己的群列表里面
 -3  上传图片失败
 -4  用户放弃当前操作
 -5  客户端内部处理错误
 */
-(void)shareSuccssWithQQCode:(NSInteger)code{
    NSLog(@"code %ld",(long)code);
    if (code == 0) {
        UIAlertView *aler = [[UIAlertView alloc]initWithTitle:@"提示" message:@"分享成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [aler show];
    }else{
        UIAlertView *aler = [[UIAlertView alloc]initWithTitle:@"提示" message:@"分享失败" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [aler show];
    }
}

上一篇 下一篇

猜你喜欢

热点阅读