iPhone崩溃,无法将base64输入到Webview [英] iPhone crash for feeding base64 to webview

查看:234
本文介绍了iPhone崩溃,无法将base64输入到Webview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UIImagePickerController选择图像/视频,选择后,我将资源转换为base64字符串,并将其发送到wkwebview

I am using UIImagePickerController to choose image/video,upon selection I am converting the resource into base64 string and I am sending that to wkwebview

NSData(contentsOfURL:(info[UIImagePickerControllerMediaURL] as? NSURL)!)?.base64EncodedDataWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)

我正在使用 evaluatejavascript

这是JS函数

function showResource(base64,type){
        if (type == "image"){
            document.getElementById("div1").innerHTML="<img src='data:image/jpeg;base64,"+base64+"' width='100' height='100' alt='No Image'/>";
        }
        else{
            document.getElementById("div1").innerHTML="<video width='320' height='240' controls><source src='data:video/x-m4v;base64,"+base64+"'></video>";
        }
}.

我面临以下问题

  • 有时Webview中的网页变为空白
  • 有时应用程序崩溃
  • 有时设备会变成多个 重新启动
  • sometimes the webpage that is in webview becomes blank
  • sometimes the application gets crashed
  • sometimes the device goes into multiple reboot

我在本机代码中找不到任何内存泄漏.我尝试了Instruments.

I couldn't find any memory leak in native code.I tried Instruments.

  • 尝试首次加载25秒长的视频时,它不会崩溃,并且您在Instruments中找不到内存泄漏
  • 再次尝试加载同一视频,结果相同
  • 尝试执行相同的操作,这次您将看到设备已脱机

  • try loading a video of 25 seconds long first time it won't crash and you can't find a memory leak in Instruments
  • try loading the same video again the results are same
  • try doing the same,this time you'll see the device has gone offline

或者,如果我们尝试加载60长的视频,它将在第一次自动崩溃.

or if we try to load a video that's 60 longs it will crash the first time itself.

我不确定是什么原因引起的.

I am not sure what's causing the problem.

由于页面空白,我认为这可能是javascript内存泄漏

As the page is turning blank , it could be a javascript memory leak I thought

但是我不认为上面的函数会导致内存泄漏,因为我们在同一个变量上重新分配了新的base64,而旧的base64应该已经从内存中释放出来了,而且javascript是垃圾回收语言.

But I don't think the above function can cause memory leak since we're reassigning the new base64 on the same variable the older base64 should have been released from the memory and moreover javascript is garbage collected language.

所以这是矛盾的.

因此,base64转换可能会占用更多内存,这反过来又会导致iOS在最坏的情况下也使应用程序崩溃或iPhone崩溃,但是如果是这种情况,那么有时html页将变为空白.

so base64 conversion might take more memory which in turn causes iOS to crash the app or crash the iPhone also in worst case but if this is the case why sometime html page is turning blank.

所以这也是矛盾的.

感谢您的帮助!

更新:

到目前为止,我的研究表明问题出在javascript中.

So far in my research it shows the problem is with memory leak in javascript.

推荐答案

如果xcode打印未分配释放的指针*在malloc_error_break中设置断点以进行调试",请尝试关闭safari Web浏览器.

If xcode print "pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug" ,try to turn off the safari web viewer.

这篇关于iPhone崩溃,无法将base64输入到Webview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆