美文网首页
ios QQ分享

ios QQ分享

作者: 未完成1307 | 来源:发表于2018-01-23 14:33 被阅读1643次

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

  • 导入SDK
    TencentOpenAPI.framework TencentOpenApi_iOS_Bundle.bundle


    导入SDK .png
  • 添加依赖库
    (记得16年第一次做 QQ分享的时候 参考的文档添加的依赖库,最后什么都配置好了,却一直分享不了。。流程检测了好几遍都没问题,也没有任何报错。。。。 无奈与官方Demo 对比 才发现文档上少写了几个库。。。。。不过 ,最近看 好像文档已经补全了。。。。。尽管文档还是很乱。。尽管官方Demo还是运行不了。。。。。)

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


添加依赖库.png
  • 添加白名单以及URL scheme
    QQ与QQ空间白名单:mqzoneopensdk、mqzoneopensdkapi、mqzoneopensdkapi19、mqzoneopensdkapiV2、mqqOpensdkSSoLogin、mqqopensdkapiV2、mqqopensdkapiV3、wtloginmqq2、mqqapi、mqqwpa、mqzone、mqq。


    白名单.png
    F4E0224D-DF0B-4096-9870-18317BEF1683.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];
    }
}

相关文章

  • iOS QQ分享、微信分享拼接appinstall参数

    标签: iOS、QQ、分享、appinstall 前几天开发,测试吐槽iOS分享链接到QQ,在QQ内打不开,当时找...

  • ios QQ分享

    QQ分享 需要配置的和微信[微信分享]https://www.jianshu.com/p/0225b32c8f1a...

  • iOS sharesdk分享qq 、

    1 10进制数转16进制数echo‘ibase=10;obase=16;801312852’|bc 网址http:...

  • iOS 配置QQ分享

    1、打开腾讯开放平台https://open.tencent.com/[https://open.tencent....

  • QQ分享

    腾讯开放平台管理中心 申请QQ分享时需要填写的URL schema 当在 iOS app 中集成qq的分享功能时,...

  • 简单实用的iOS分享方式iOS_Share

    搞iOS开发的人,都会碰到一个问题,就是iOS分享,主要是分享到微信、QQ、新浪微博等社交媒体。分享实现的方式有以...

  • 友盟分享qq错误码:9001007

    用友盟集成QQ分享,遇到QQ好友分享提示 第三方app没有权限 错误码:9001007 iOS上线发布后,才能正常...

  • iOS 微信、QQ分享

    对于分享一事,估计都做过。这里记录一下 微信 不得不说 微信的文档写的很详细 Demo 也易懂。集成很快的。具...

  • IOS QQ原生登录、分享

    一、QQ登录 准备工作 1、到QQ开放平台(http://connect.qq.com/ )注册成为开发者,申请a...

  • iOS集成QQ分享,包括QQ好友和QQ动态

    一、导入QQ分享工具类 pod TencentOpenAPI 二、写QQ分享的工具类 QQ好友和动态 QQShar...

网友评论

      本文标题:ios QQ分享

      本文链接:https://www.haomeiwen.com/subject/npgihttx.html