1

インターネットから 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];
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 に答える