QQ分享的简单应用

QQ分享的简单应用

在腾讯开放平台申请应用,拿到需要的appId,下载最新的QQ分享sdk导入工程中
1.添加SDK依赖的系统库文件:
Security.framework”, “libiconv.dylib”,“SystemConfiguration.framework”,“CoreGraphics.Framework”、“libsqlite3.dylib”、“CoreTelephony.framework”、“libstdc++.dylib”、“libz.dylib”

2.在工程配置中的“Build Settings”一栏中找到“Linking”配置区,给“Other Linker Flags”配置项添加属性值“-fobjc-arc”。

3…添加URL types,采用的是“tencent”+appId的组合scheme

在这里插入图片描述4.添加白名单,使手机能调用QQ
在这里插入图片描述<key>LSApplicationQueriesSchemes</key> <array> <string>mqqapi</string> <string>mqq</string> <string>mqqOpensdkSSoLogin</string> <string>mqqconnect</string> <string>mqqopensdkdataline</string> <string>mqqopensdkgrouptribeshare</string> <string>mqqopensdkfriend</string> <string>mqqopensdkapi</string> <string>mqqopensdkapiV2</string> <string>mqqopensdkapiV3</string> <string>mqzoneopensdk</string> <string>wtloginmqq</string> <string>wtloginmqq2</string> <string>mqqwpa</string> <string>mqzone</string> <string>mqzonev2</string> <string>mqzoneshare</string> <string>wtloginqzone</string> <string>mqzonewx</string> <string>mqzoneopensdkapiV2</string> <string>mqzoneopensdkapi19</string> <string>mqzoneopensdkapi</string> <string>mqzoneopensdk</string> </array>

5.开始使用
在Appdelegate.m中导入需要的头文件

在这里插入图片描述
注册QQ

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    //注册本地消息推送
    [Publicmethods registerLocalNotification:application];
    //[Publicmethods addLocalNotification:@"haha, 您有一个新的消息。" alertAction:@"打开应用" timeInterval:1.0 isSound:[ShareData sharedSingleton].globalIsSound soundID:[ShareData sharedSingleton].globalSystemSoundID isVibration:[ShareData sharedSingleton].globalIsVibration];
    
    //检查手机设备类型
    [self checkDeviceType];
    
    //启动第三方平台蒲公英SDK,利用其进行软件检测更新
    //[self PgyManager];
    
    //向微信注册:必须真机调试,并且装有微信
    [WXApi registerApp:kWeixinAppID];
    
    //QQ注册
    [[TencentOAuth alloc]initWithAppId:QQOpenId andDelegate:nil];

重写HandleUrl方法

pragma mark - 微信weixin,QQ
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    if ([url.scheme isEqualToString:kWeixinAppID]) {
        return  [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
        
    }else if ([url.scheme isEqualToString:[NSString stringWithFormat:@"tencent%@",QQOpenId]])    //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.scheme isEqualToString:kWeixinAppID]) {
        return  [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
        
    }else if ([url.scheme isEqualToString:[NSString stringWithFormat:@"tencent%@",QQOpenId]])    //QQ
    {
        return [QQApiInterface handleOpenURL:url delegate:self];
    }else{
        return YES;
    }
}

在需要点击QQ分享的ViewController中
执行需要入参,发送消息

//QQ分享
- (void)showMediaNewsWithScene:(int)scene
{
    if (![TencentOAuth iphoneQQInstalled]) {
        //初始化提示框
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"没有检测手机里安装了QQ应用程序,请先安装" preferredStyle: UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //点击按钮的响应事件
            NSLog(@"ok");
        }]];
        //弹出提示框;
        [self presentViewController:alert animated:true completion:nil];
    }else {
        //self.tencentOAuth = [[TencentOAuth alloc] initWithAppId:QQAPPID
        //                                            andDelegate:self];
        
        //        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        //        NSString *documentsDirectory = [paths objectAtIndex:0];
        //        NSLog(@"%@",documentsDirectory);
        //        NSString *filePath = [NSString stringWithFormat:@"%@/%@",documentsDirectory, kQRCodeFileName];
        
      
//        UIImage* image = [Publicmethods imageWithFileName:kQRCodeFileName];
//            if (!image)
//                return;
        UIImage *image=[UIImage imageNamed:@"80_4.png"];
        NSData *imageData = UIImagePNGRepresentation(image);
        
        NSString *urlString=[[NSUserDefaults standardUserDefaults]objectForKey:@"versionURL"];  //下载地址
        
        //分享app下载链接
        QQApiNewsObject *newsObj = [QQApiNewsObject
                                    objectWithURL:[NSURL URLWithString:urlString]
                                    title:@"软件分享:壹家医宝医生端"
                                    description:@"整合式、流程化家庭医生服务管理,助力医改新模式"
                                    previewImageData:imageData];
        
        SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];
        if (scene == 0) {
            NSLog(@"QQ好友列表分享 - %d",[QQApiInterface sendReq:req]);
        }else if (scene == 1){
            NSLog(@"QQ空间分享 - %d",[QQApiInterface SendReqToQZone:req]);
        }
        
        /*
        //分享二维码图片
        QQApiImageObject *imgObj = [QQApiImageObject objectWithData:imageData
                                                   previewImageData:imageData
                                                              title:@"扫一扫"
                                    
                                                        description:@"下载壹家医宝(医生端APP)"];
        
        SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:imgObj];
        
        //将内容分享到qq
        
        QQApiSendResultCode sent = [QQApiInterface sendReq:req];
        */
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的自定义微信和 QQ 分享组件的案例: 1. 引入相应的 SDK 或插件,并在 HTML 中添加分享按钮。 ```html <!-- 引入微信 SDK --> <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script> <!-- 引入 QQ SDK --> <script src="http://qzonestyle.gtimg.cn/qzone/qzact/act/qqconnect.js"></script> <!-- 添加分享按钮 --> <button class="share-btn" data-type="wx">分享到微信</button> <button class="share-btn" data-type="qq">分享QQ</button> ``` 2. 在 JavaScript 中配置分享内容和分享接口。 ```javascript // 配置微信分享 wx.config({ appId: 'your_app_id', timestamp: 'your_timestamp', nonceStr: 'your_nonce_str', signature: 'your_signature', jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'] }); // 配置 QQ 分享 QC.api("share", { title: "分享标题", desc: "分享描述", imgUrl: "分享图片链接", url: "分享链接" }); // 监听分享按钮点击事件 document.querySelectorAll('.share-btn').forEach(function(btn) { btn.addEventListener('click', function(e) { var type = e.target.dataset.type; if (type === 'wx') { // 分享到微信 wx.updateAppMessageShareData({ title: '分享标题', desc: '分享描述', link: '分享链接', imgUrl: '分享图片链接', success: function () { // 分享成功后的回调函数 } }); } else if (type === 'qq') { // 分享QQ QC.share(); } }); }); ``` 注意:以上代码仅作为示例,实际应用中需要根据具体的需求进行调整和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值