The project needs to generate growth map and save to local or share the function

Without further ado, here is the code for the relevant logic:

Because the web page is not necessarily a screen height, generally beyond the screen height, here it is necessary to judge the increase in height.

- (UIImage *)snapshotViewFromRect:(CGRect)rect withCapInsets:(UIEdgeInsets)capInsets {
    
    CGFloat scale = [UIScreen mainScreen].scale;
    
    CGSize boundsSize = self.web.bounds.size;
    CGFloat boundsWidth = boundsSize.width;
    CGFloat boundsHeight = boundsSize.height;
    
    CGSize contentSize = self.web.scrollView.contentSize;
    CGFloat contentHeight = contentSize.height;
    CGFloat contentWidth = contentSize.width;
    
    CGPoint offset = self.web.scrollView.contentOffset;

    [self.web.scrollView setContentOffset:CGPointMake(0, 0)];
    
    NSMutableArray *images = [NSMutableArray array];
    while(contentHeight > 0) { UIGraphicsBeginImageContextWithOptions(boundsSize, NO, [UIScreen mainScreen].scale); // Render webView in the current context // If you take webView.scrollView.layer, the data beyond one screen will not be displayed, only the white area block [self.web.layer] will be displayed renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [images addObject:image]; CGFloat offsetY = self.web.scrollView.contentOffset.y; // Set the webView offset [self.web.scrollView]setContentOffset:CGPointMake(0, offsetY + boundsHeight)];
        contentHeight -= boundsHeight;
    }
    
    
    [self.web.scrollView setContentOffset:offset]; CGSize imageSize = CGSizeMake(contentSize.width * scale, contentSize.height * scale); UIGraphicsBeginImageContext(imageSize); [images enumerateObjectsUsingBlock:^(UIImage *image, NSUInteger idx, BOOL *stop) { [image drawInRect:CGRectMake(0, scale * boundsHeight * idx, scale * boundsWidth, scale * boundsHeight)]; }]; / / interception of the current context generated Image UIImage * fullImage = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext(); UIImageView *snapshotView = [[UIImageView alloc]initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)]; snapshotView.image = [fullImage resizableImageWithCapInsets:capInsets];
    
    return snapshotView.image;
}

Copy the code

After the growth map to share pictures: here is the use of friends sharing, sharing pictures do not have to download and store pictures,

@property (nonatomic,strong) UIImage *shareImage; // Generate growth diagramCopy the code
/ / image sharing - (void) shareImageToPlatformType: UMSocialPlatformType platformType {/ / UMSocialMessageObject create share the message object *messageObject = [UMSocialMessageObject messageObject]; UMShareImageObject *shareObject = [UMShareImageObject alloc] init]; // ShareObject. thumbImage = [UIImage imageNamed:@"AppIcon"]; // Set the image [shareObject] to sharesetShareImage:self.shareImage]; / / share the message object set share content object messageObject shareObject = shareObject; / / call sharing interface [[UMSocialManager defaultManager] shareToPlatform: platformType messageObject: messageObject currentViewController:self completion:^(id data, NSError *error) {if (error) {
            ZLLog(@"************Share fail with error %@*********",error);
        }else{
            ZLLog(@"response data is %@",data); }}]; }Copy the code

There is also a need to save the growth map locally:

- (void)screenshotPic { CGRect snapshotFrame = CGRectMake(0, 0, _web.scrollView.contentSize.width, _web.scrollView.contentSize.height); UIEdgeInsets snapshotEdgeInsets = UIEdgeInsetsZero; UIImage *shareImage = [self snapshotViewFromRect:snapshotFrame withCapInsets:snapshotEdgeInsets]; self.shareImage = shareImage; / / stored in the photo album UIImageWriteToSavedPhotosAlbum (shareImage, self, nil, NULL); // dispatch_after(dispatch_time(DISPATCH_TIME_NOW), (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{MBProgressHUD showSuccess:@"Saved to album"];
//    });
    
}
Copy the code

Click save album here to find the flash back. The following error was found in Xcode:

This app has crashed because it attempted to access privacy-sensitive data without a usage description.  The app's Info.plist must contain an NSPhotoLibraryAddUsageDescription key with a string value explaining to the user how the app uses this data.
Copy the code

The problem is the same with iOS 10 when saving images and calling the camera, info.plist adds a message when it comes to private data. Open info.plist, click the + sign and Type in Key: privacy-Photo Library Additions Usage Description, Type select String, and enter your prompt in Value.

This is a new privacy rule for iOS 11, and it says as follows: IOS11, apple’s album access key for the adjustment, the original NSPhotoLibraryUsageDescription, after iOS11, changed to NSPhotoLibraryAddUsageDescription

IOS 11 new privacy Settings iOS 11 new add another associated with NFC device NFCReaderUsageDescription, but didn’t come into contact with for the time being.