我就直接贴代码了,copy后放入按钮中即可用
-(void)shareWXButton{
UIImage *image = [self snapsHotView:self.view];
NSData* imageData = UIImagePNGRepresentation(image);
WXImageObject *imageObject = [WXImageObject object];
imageObject.imageData = imageData;
WXMediaMessage *message = [WXMediaMessage message];
message.mediaObject = imageObject;
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.bText = NO;
req.message = message;
req.scene = WXSceneTimeline;
[WXApi sendReq:req completion:^(BOOL success) {
NSLog(@"分享完成");
}];
}
- (UIImage*)snapsHotView:(UIView *)view{
UIGraphicsBeginImageContextWithOptions(view.bounds.size,NO,[UIScreen mainScreen].scale);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
问题一:点击按钮后直接显示分享成功,不跳转微信。
问题二: PBItemCollectionServicer connection disconnected. 报错。
问题三:由于不支持的分享类型,【返回(未审核应用)】。
图片: