做法就是将 Cocos Creator 的整个Canvas的内容转化成base64图片编码;然后传至iOS客户端,再还原成图片即可
注册监听(需要用到交互)
[[self._webView configuration].userContentController addScriptMessageHandler:self name:@"SharedApp"];
1、iOS 代码
+ (void)saveTextureToLocal:(NSString*)type{
NSArray *imageArray = [type componentsSeparatedByString:@","];
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:imageArray[1] options:NSDataBase64DecodingIgnoreUnknownCharacters];
UIImage *image = [UIImage imageWithData:imageData];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
};
2、修改Info.plist配置
添加 Privacy - Photo Library Additions Usage Description 权限