我的應用有一個邀請好友的頁面,需要調用分享,直接看代碼
//分享的标題
NSString *textToShare = @“邀請好友”;
UICollectionViewCell *shareCell = [self.cycleScrollView3.collectionView cellForItemAtIndexPath:indexPath];
UIImage *shareImg = [self convertViewToImage:shareCell.contentView];
if (shareImg == nil) {
[self showWithLabel:@“分享失敗”];
return;
}
NSData * shareData = UIImageJPEGRepresentation(shareImg, 0.5);
NSArray *activityItems = @[textToShare,shareData];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
// 分享之後的回調
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
if (completed) {
NSLog(@“completed”);
//分享 成功
} else {
NSLog(@“cancled = %@”,activityError);
//分享 取消
}
};
然後點選微信去分享,在非劉海屏手機大概10%以下機率回遇到下面這種情況,在劉海屏大概30%到機率,求大佬解惑