简单应用"/>
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 = [QQApiNewsObjectobjectWithURL:[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:imageDatapreviewImageData:imageDatatitle:@"扫一扫"description:@"下载壹家医宝(医生端APP)"];SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:imgObj];//将内容分享到qqQQApiSendResultCode sent = [QQApiInterface sendReq:req];*/}
}
更多推荐
QQ分享的简单应用
发布评论