要在appdelegate里实现这两个方法,特别是下面的那个,如果是iOS9 一定要实现 否则不走回调。
//@implementation AppDelegate (UMeng)
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
return [UMSocialSnsService handleOpenURL:url];
}
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options{
return [UMSocialSnsService handleOpenURL:url];
}
//网页分享
- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType url:(NSString *)url title:(NSString *)title description:(NSString *)description
{
//创建分享消息对象
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary];
NSString *icon = [[infoPlist valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
UIImage* image = [UIImage imageNamed:icon];
//创建网页内容对象
UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:description thumImage:image];
//设置网页地址
shareObject.webpageUrl = url;
//分享消息对象设置分享内容对象
messageObject.shareObject = shareObject;
MPWeakSelf(self);
//调用分享接口
[[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
if (error) {
UMSocialLogInfo(@"************Share fail with error %@*********",error);
[MBProgressHUD showSuccess:@"分享失败" ToView:weakself.view];
}else{
[MBProgressHUD showSuccess:@"分享成功" ToView:weakself.view];
//
// if ([data isKindOfClass:[UMSocialShareResponse class]]) {
// UMSocialShareResponse *resp = data;
// //分享结果消息
// UMSocialLogInfo(@"response message is %@",resp.message);
// //第三方原始返回的数据
// UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
//
// }else{
// UMSocialLogInfo(@"response data is %@",data);
// }
}
}];
}