对于分享一事,估计都做过。这里记录一下
微信
不得不说 微信的文档写的很详细 Demo 也易懂。集成很快的。具体的流程照着文档一步一步来就可以了 [参考链接]https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=1417694084&token=&lang=zh_CN
这记录几个点
将Demo中的SDK 拖入工程中 (手动集成)
libWeChatSDK.a,WXApi.h,WXApiObject.h-
导入相关库
SystemConfiguration.framework, libz.dylib, libsqlite3.0.dylib, libc++.dylib, Security.framework, CoreTelephony.framework, CFNetwork.framework
-
选择Build Setting,在"Other Linker Flags"中加入"-Objc -all_load"
-
添加“URL scheme
值得注意的是 要实现应用间跳转 别忘了添加URLScheme
-
添加白名单
从iOS9.0后,涉及到平台客户端的跳转
微信白名单:wechat、weixin。
相关代码
注册
//向微信注册
[WXApi registerApp:WECHAT_APP_ID];
//向微信注册支持的文件类型
//----------------------------微信
UInt64 typeFlag = MMAPP_SUPPORT_TEXT | MMAPP_SUPPORT_PICTURE | MMAPP_SUPPORT_LOCATION | MMAPP_SUPPORT_VIDEO |MMAPP_SUPPORT_AUDIO | MMAPP_SUPPORT_WEBPAGE | MMAPP_SUPPORT_DOC | MMAPP_SUPPORT_DOCX | MMAPP_SUPPORT_PPT | MMAPP_SUPPORT_PPTX | MMAPP_SUPPORT_XLS | MMAPP_SUPPORT_XLSX | MMAPP_SUPPORT_PDF;
[WXApi registerAppSupportContentFlag:typeFlag];
//-------------------------微信end
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
NSString *path = [url absoluteString];
if ([path hasPrefix:@"tencent"]) {
// 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];
}
else if([path hasPrefix:@"wx"]) {
return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
}
return YES;
}
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
NSString *path = [url absoluteString];
if ([path hasPrefix:@"tencent"]){
// return[TencentOAuth HandleOpenURL:url];
}
else if([path hasPrefix:@"wx"]) {
return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
}
return YES;
}
刚也提到了,微信不管文档还是Demo 都写的喊详细 具体方法参照文档就好 。
微信的demo里做了很好的封装 我就直接拷进我的项目里了
具体实现(这里只记录了其中一种分享方式 其他的参考文档)
if ([WXApi isWXAppInstalled]==NO) {
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的设备未安装微信" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
[msgbox show];
}
//图片链接
NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",_webModel.image]]];
[WXApiRequestHandler sendLinkURL:_webModel.url
TagName:nil
Title: _webModel.title
Description:_webModel.content
ThumbImage:[UIImage imageWithData:imgData]
InScene:WXSceneSession];
发送到聊天界面——WXSceneSession
发送到朋友圈——WXSceneTimeline
添加到微信收藏——WXSceneFavorite
分享之后的回调
//返回 回来的结果 发送是否成功
- (void)managerDidRecvMessageResponse:(SendMessageToWXResp *)response {
if (response.errCode == 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];
}
}