Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController to share images to WeChat not work

When I use Apple's UIActivityViewController to share a few images to WeChat (weixin). I find that sometimes it doesn't work. Most of the time it works well when I select only 1~3 images, but if I share 9 images (largest number allowed by WeChat), it will certainly fail, and the console will print

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

Here is the code:

__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 is the custom object that implemented the protocol UIActivityItemSource.

P.S. I tried APP Google Photo and found it has done very well in its share function. It can share 9 images with even original HD size of system photo asserts to WeChat using UIActivityViewController. So, how should I solve this problem?

like image 977
catlee Avatar asked Apr 01 '16 08:04

catlee


1 Answers

WeChat's Share Extension is Terminated due to App Extension's Memory Limit.
According to Apple's App Extension Programming Guide: Optimize Efficiency and Performance

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.I created 9 very small images,and shared with WeChat successfully:

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

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

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

  return image;
}    

2.You can scale down your images before sharing them with WeChat,here is some Scale methods

like image 118
wj2061 Avatar answered Oct 02 '22 10:10

wj2061