嗨,我正在尝试使用UIActivityController与微信用户共享图像URL和描述,但是它无法共享图像。我尝试使用以下代码:
UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:@[@"TestMessage", [UIImage imageNamed:@"pauseImage"], [NSURL URLWithString:@"http://www.google.com"]] applicationActivities:nil];
activityView.excludedActivityTypes = @[UIActivityTypeAssignToContact,
UIActivityTypeCopyToPasteboard, UIActivityTypePrint];
[self presentViewController:activityView animated:YES completion:nil];
我得到的输出如下图所示:
任何帮助或建议,将不胜感激。谢谢。
最佳答案
在Swift中,以下代码对我有用。
抱歉,我在Objective C中没有确切的代码,但我认为这可能也会有所帮助。
let objectsToShare : NSMutableArray = NSMutableArray()
//add title and description
objectsToShare.addObject(titleToShare)
objectsToShare.addObject(myWebsite)
if(self.pageThumbImage.image != nil)
{
//here pageThumbImage is an UIImageView object
objectsToShare.addObject(self.pageThumbImage.image!)
}
let activityVC = ActivityViewController(activityItems: objectsToShare as [AnyObject], applicationActivities: nil)
//New Excluded Activities Code
activityVC.excludedActivityTypes = [UIActivityTypeAirDrop, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypeCopyToPasteboard,
UIActivityTypeSaveToCameraRoll, UIActivityTypeAssignToContact, UIActivityTypeMessage,
UIActivityTypeMail, UIActivityTypePostToTwitter]
activityVC.popoverPresentationController?.sourceView = sender as? UIView
self.presentViewController(activityVC, animated: true, completion: nil)