1

我想把网上的一张照片分享到微信上,但是按下分享按钮后,什么都没有发生,我是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];
4

1 回答 1

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];
}
}
于 2013-11-19T14:23:07.987 回答