未能将我的照片分享给WECHAT

时间:2012-11-01 08:23:23

标签: ios iphone

我想从互联网上分享一张照片给WECHAT,但是按下分享按钮后没有任何反应,我是Objective-C的新手,我自己无法弄清楚问题。听说有很多这里的专家,那么有些人可以帮我解决这个问题吗?提前致谢。这是代码:

UIImage * image = [[[imageTitleArray objectAtIndex:initIndex] albumImageView] image];
       WXMediaMessage *message = [WXMediaMessage message];
       [message setThumbImage: image];
       WXImageObject *ext = [WXImageObject object];
       ext.imageData =  UIImageJPEGRepresentation(image,1);
       message.mediaObject = ext;
       SendMessageToWXReq* req = [[[SendMessageToWXReq alloc] init]autorelease];
       req.bText = NO;
       req.message = message;
       [WXApi sendReq:req];

1 个答案:

答案 0 :(得分:1)

尝试以下方法

- (void) sendImageContentToWeixin:(UIImage *)image {
//if the Weixin app is not installed, show an error
if (![WXApi isWXAppInstalled]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"The Weixin app is not installed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
return;
}
//create a message object
WXMediaMessage *message = [WXMediaMessage message];
//set the thumbnail image. This MUST be less than 32kb, or sendReq may return NO.
//we'll just use the full image resized to 100x100 pixels for now
[message setThumbImage:[image resizedImage:CGSizeMake(100,100) interpolationQuality:kCGInterpolationDefault]];
//create an image object and set the image data as a JPG representation of our UIImage
WXImageObject *ext = [WXImageObject object];
ext.imageData = UIImageJPEGRepresentation(image, 0.8);
message.mediaObject = ext;
//create a request
SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
//this is a multimedia message, not a text message
req.bText = NO;
//set the message
req.message = message;
//set the "scene", WXSceneTimeline is for "moments". WXSceneSession allows the user to send a message to friends
req.scene = WXSceneTimeline;
//try to send the request
if (![WXApi sendReq:req]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Error" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
}