保存h5中的图片到本地
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#import "XPMineUserInfoViewController.h"
|
||||
#import "XPMineRechargeViewController.h"
|
||||
#import "NSMutableDictionary+Saft.h"
|
||||
#import "Base64.h"
|
||||
///vc
|
||||
#import "XPMineDressUpViewController.h"
|
||||
#import "XPDressUpShopViewController.h"
|
||||
@@ -96,6 +97,7 @@ NSString * const kJumpAppointPage = @"jumpAppointPage";
|
||||
NSString * const kJSOpenRoom = @"openRoom";
|
||||
NSString * const kJSOpenRoomForGiftId = @"openRoomForGiftId";
|
||||
NSString * const kProhibitRightSlip = @"prohibitRightSlip";
|
||||
NSString * const kSaveBase64Image = @"saveBase64Image";
|
||||
|
||||
@implementation XPWebViewController
|
||||
|
||||
@@ -342,12 +344,34 @@ NSString * const kProhibitRightSlip = @"prohibitRightSlip";
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
} else if([message.name isEqualToString:kSaveBase64Image]) {
|
||||
NSString * base64 = message.body;
|
||||
NSArray * array = [base64 componentsSeparatedByString:@","];
|
||||
if(array.count > 1) {
|
||||
NSData * data = [Base64 decode:array[1]];
|
||||
UIImage * image = [UIImage imageWithData:data];
|
||||
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (__bridge void *)self);
|
||||
}
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - private method
|
||||
|
||||
#pragma mark - private metho
|
||||
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
|
||||
if (error == nil) {
|
||||
NSString * jsStrUrl = [NSString stringWithFormat:@"saveBase64ImageCallback(\"%@\")", @"1"];
|
||||
[self.webview evaluateJavaScript:jsStrUrl completionHandler:^(id _Nullable other, NSError * _Nullable error) {
|
||||
NSLog(@"%@",error);
|
||||
}];
|
||||
} else {
|
||||
NSString * jsStrUrl = [NSString stringWithFormat:@"saveBase64ImageCallback(\"%@\")", @"0"];
|
||||
[self.webview evaluateJavaScript:jsStrUrl completionHandler:^(id _Nullable other, NSError * _Nullable error) {
|
||||
NSLog(@"%@",error);
|
||||
}];
|
||||
}
|
||||
}
|
||||
- (void)handleRouterType:(NSInteger)skyType message:(WKScriptMessage *)message {
|
||||
NSDictionary *bodyDict;
|
||||
if ([message.body isKindOfClass:[NSDictionary class]]) {
|
||||
@@ -657,6 +681,8 @@ NSString * const kProhibitRightSlip = @"prohibitRightSlip";
|
||||
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSOpenRoomForGiftId];
|
||||
///禁用侧滑手势
|
||||
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kProhibitRightSlip];
|
||||
///保存图片到本地
|
||||
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kSaveBase64Image];
|
||||
}
|
||||
return _userContentController;
|
||||
}
|
||||
|
Reference in New Issue
Block a user