参考友盟的文档做的
AppDelegate.m
一、
//登陆友盟 注册应用获取的AppKey
[UMSocialData setAppKey:@"507fcab25270157b37000010"];
//微信开放平台注册应用 获取的AppId appSecret
[UMSocialWechatHandler setWXAppId:@"wx4bbba3c3a96eb5a1" appSecret:@"d4624c36b6795d1d99dcf0547af5443d" url:@"http://m.yuanpin1.com"];
//(2)处理程序间回调(头像等)
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [UMSocialSnsService handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [UMSocialSnsService handleOpenURL:url];
}
二、
在TARGETS --- info ---- URL Types 填写微信开放平台注册应用 获取的AppId appSecret
三 、 在viewcontroller.m
设置三个imageview
if (imgae.tag == 1300) {
NSLog(@"微信好友");
// UMShareToWechatSession,UMShareToWechatTimeline,UMShareToWechatFavorite分别代表微信好友、微信朋友圈、微信收藏
[[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToWechatSession] content:content image:shareImage location:nil urlResource:urlR presentedController:self completion:^(UMSocialResponseEntity *response){
if (response.responseCode == UMSResponseCodeSuccess) {
}
}];
}
if (imgae.tag == 1301) {
NSLog(@"微信朋友圈");
[[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToWechatTimeline] content:content image:shareImage location:nil urlResource:urlR presentedController:self completion:^(UMSocialResponseEntity *response){
if (response.responseCode == UMSResponseCodeSuccess) {
NSLog(@"分享成功!");
}
}];
}if (imgae.tag == 1302) {
NSLog(@"微信收藏");
[[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToWechatFavorite] content:content image:shareImage location:nil urlResource:urlR presentedController:self completion:^(UMSocialResponseEntity *response){
if (response.responseCode == UMSResponseCodeSuccess) {
NSLog(@"分享成功!");
}
}];
}
}
//实现回调方法(可选):
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
//根据`responseCode`得到发送结果,如果分享成功
if(response.responseCode == UMSResponseCodeSuccess)
{
//得到分享到的微博平台名
NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
}
}