ios – UIActivityViewController将图像分享到微信无法正常工作

当我使用Apple的UIActivityViewController与WeChat(weixin)共享一些图像时.我发现有时它不起作用.大多数情况下,当我只选择1~3张图像时效果很好,但如果我共享9张图片(微信允许的最大数量),它肯定会失败,控制台会打印出来

2016-04-01 16:14:34.258 EverPhoto[5567:1981394] plugin
com.tencent.xin.sharetimeline interrupted 2016-04-01 16:14:34.258
EverPhoto[5567:1981394] plugin com.tencent.xin.sharetimeline
invalidated

这是代码

__weak typeof(self) __weakSelf = self;
self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:self.shareItems applicationActivities:nil];
self.activityViewController.excludedActivityTypes = @[UIActivityTypePostToFacebook,UIActivityTypePostToTwitter,UIActivityTypePostToVimeo,UIActivityTypePostToTencentWeibo,UIActivityTypePrint,UIActivityTypecopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSavetoCameraRoll,UIActivityTypeAddToReadingList,UIActivityTypePostToFlickr,];
self.activityViewController.completionWithItemsHandler = ^(Nsstring * __nullable activityType,BOOL completed,NSArray * __nullable returnedItems,NSError * __nullable activityError){
    DLog(@"shareCompleted : %@",completed ? @"YES" : @"NO")
    __weakSelf.shareItems = nil;
    __weakSelf.activityViewController = nil;
};

[self.containerVc presentViewController:self.activityViewController animated:YES completion:nil];

ShareItems是实现协议UIActivityItemSource的自定义对象.

附:我尝试了APP Google Photo,发现它在共享功能方面做得很好.它可以使用UIActivityViewController与WeChat共享9张图像,甚至是原始高清尺寸的系统照片断言.
那么,我该如何解决这个问题呢?

解决方法

由于App Extension的内存限制,微信的共享扩展已终止.
根据Apple的 App Extension Programming Guide:优化效率和性能

Memory limits for running app extensions are significantly lower than the memory limits imposed on a foreground app. On both platforms,the system may aggressively terminate extensions because users want to return to their main goal in the host app. Some extensions may have lower memory limits than others: For example,widgets must be especially efficient because users are likely to have several widgets open at the same time.

1.我创建了9个非常小的图像,并与微信成功分享

- (UIImage *)imageWithColor:(UIColor *)color
{
  CGRect rect = CGRectMake(0,1,1);
  UIGraphicsBeginImageContext(rect.size);
  CGContextRef context = UIGraphicsGetCurrentContext();

  CGContextSetFillColorWithColor(context,[color CGColor]);
  CGContextFillRect(context,rect);

  UIImage *image = UIGraphicsGetimageFromCurrentimageContext();
  UIGraphicsEndImageContext();

  return image;
}

2.在与微信分享之前,您可以缩小图像,这里是Scale methods

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...