集成腾讯官方QQ和QQ空间分享的方法

1.在腾讯官网申请APP ID APP KEY

2.添加URL type

v URL Types (3) weixin No image specified Identifier Icon weixin None Additional url type properties tencent No image specified Identifier Icon tencent None Additional url type properties (O) QQ No specifie Identifier Icon QQ None URL Schemes Role URL Schemes Role URL Schemes Role wxe27d035b12e64362 Editor tencent1104757171 Editor QQ41D941B3 Editor Additional url type properties (O)

3.将系统库文件TencentOpenApi_IOS_BundleTencentOpenAPI集成到项目中

4.添加SDK依赖的系统库文件

“Security.framework”、“libiconv.dylib”、“SystemConfiguration.framework”、“CoreGraphics.Framework”、“libsqlite3.dylib”、“CoreTelephony.framework”、“libstdc++.dylib”、“libz.dylib”

5.在AppDelegate.h中 导入 头文件

a.导入头文件

#import <TencentOpenAPI/TencentOAuth.h>

#import <TencentOpenAPI/QQApiInterface.h>

b.添加属性

@property (nonatomic, strong) TencentOAuth *oauth;

c.app代理方法中注册QQ

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

    self.oauth = [[TencentOAuth alloc] initWithAppId:@"1104757171" andDelegate:self];

    self.oauth.redirectURI = nil;

}

6.info.plist中的LSApplicationQueriesSchemes中添加如下字段:

LSApplicationQueriesSchemes Item O Item 1 Item 2 Item 3 Item 4 Item 5 Item 6 Item 7 Item 8 Item 9 Item 10 Item 11 Item 12 Item 13 Item 14 Item 15 Item 16 Item 17 Item 18 Item 19 Item 20 Item 21 Item 22 Item 23 Item 24 Item 25 Item 26 Item 27 Item 28 Item 29 Item 30 Array String String String String String String String String String String String String String String String String String String String String String String String String String String String String String String String (31 items) weixin wechat mqq mqqapi mqqwpa mqqbrowser mttbrowser mqqOpensdkSSoLogin mqqopensdkapiV2 mqqopensdkapiV3 mqqopensdkapiV4 wtloginmqq2 mqzone mqzoneopensdk mqzoneopensdkapi mqzoneopensdkapi19 mqzoneopensdkapiV2 mqqapiwallet mqqopensdkfriend mqqopensdkdataline mqqgamebindinggroup mqqopensdkgrouptribeshare tencentapi.qq.reqContent tencentapi.qzone.reqContent mqqconnect mqqopensdkapi wtloginmqq mqzonev2 mqzoneshare wtloginqzone mqzonewx

7.在需要分享到QQQQ空间的地方写如下代码

#pragma mark - 分享到手机QQ

- (void)clickShareMobileQQ:(NSNotification *)note {

    if (![TencentOAuthiphoneQQInstalled]) {

        [WJShowHUD showMessageWithString:@"请移步App Store去下载手机QQ"];

    } else {

        NSString *urlLink = [[NSString alloc] init];

        if([[AppDelegatesharedInstance].title isEqualToString:@"哈哈哈"]) {

            [AppDelegate sharedInstance].redPap = @"哈哈哈";

            NSString *shareTitle = @"哈哈哈";

            self.shareTitle =shareTitle;

            urlLink = self.shareLink;

        } else {

            [AppDelegate sharedInstance].redPap = @"";

            self.shareTitle = [AppDelegate sharedInstance].title != nil ? [AppDelegate sharedInstance].title : @"";

            urlLink = [AppDelegate sharedInstance].link != nil ? [AppDelegate sharedInstance].link : @"";

       }

        NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"share.png"];

        NSData* data = [NSData dataWithContentsOfFile:path];

        QQApiNewsObject *obj =[QQApiNewsObject objectWithURL:[NSURL URLWithString:urlLink] title:self.shareTitledescription:@""previewImageData:data];

        SendMessageToQQReq*req = [SendMessageToQQReq reqWithContent:obj];

        QQApiSendResultCodesent = [QQApiInterface sendReq:req];

        [self handleSendResult:sent];

   }

    self.tempBtn.hidden = YES;

    self.tempView.hidden = YES;

}

 

- (void)handleSendResult:(QQApiSendResultCode)sendResult {

    switch (sendResult)

   {

        case EQQAPIAPPNOTREGISTED:

       {

            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"App未注册" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

            [msgbox show];

           

           

           

            break;

       }

        case EQQAPIMESSAGECONTENTINVALID:

        case EQQAPIMESSAGECONTENTNULL:

        case EQQAPIMESSAGETYPEINVALID:

       {

            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

            [msgbox show];

           

            break;

       }

        case EQQAPIQQNOTINSTALLED:

       {

            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"未安装手Q" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

            [msgbox show];

           

            break;

       }

        case EQQAPIQQNOTSUPPORTAPI:

       {

            UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"API接口不支持" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

            [msgbox show];

           

            break;

       }

        case EQQAPISENDFAILD:

       {

            UIAlertView *msgbox =[[UIAlertView alloc] initWithTitle:@"Error" message:@"发送失败" delegate:nilcancelButtonTitle:@"取消" otherButtonTitles:nil];

           [msgbox show];

           

            break;

       }

        caseEQQAPIVERSIONNEEDUPDATE:

       {

            UIAlertView *msgbox =[[UIAlertView alloc] initWithTitle:@"Error" message:@"当前QQ版本太低,需要更新" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

           [msgbox show];

           

            break;

       }

        default:

       {

            break;

       }

   }

}

8.app代理方法中写如下分享后的回调方法

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {

    if ([url.schemeisEqualToString:@"wxe27d035b12e64362"]) {

        //微信分享

        return [WXApi handleOpenURL:urldelegate:self];

    } elseif ([url.schemeisEqualToString:@"QQ41D941B3"]){

        //QQ分享

        return [QQApiInterface handleOpenURL:url delegate:self];

    } else {

        return YES;

   }

}

 

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

    if ([url.schemeisEqualToString:@"wxe27d035b12e64362"]) {

        //微信分享

        return [WXApi handleOpenURL:urldelegate:self];

    } elseif ([url.schemeisEqualToString:@"QQ41D941B3"]){

        //QQ分享

        return [QQApiInterface handleOpenURL:url delegate:self];

    } else {

        return YES;

   }

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值