I have an hybrid app that works perfectly on iOS 7 using Cordova 3.7 and jQuery Mobile 1.3.2
我有一个混合应用程序,在iOS 7中使用Cordova 3.7和jQuery Mobile 1.3.2完美地运行。
I am testing it on iOS 8 and it is broken. I am requesting each page(view) of my app using absolute paths, using the file://
protocol, like:
我在ios8上测试它,它坏了。我请求使用绝对路径的应用程序的每一个页面(视图),使用文件://协议,比如:
file:///var/mobile/Applications/<UUID>/MyApp.app/www/views/add-project.html
文件:/ / / var /移动/应用程序/ < UUID > / / add-project.html MyApp.app / www /视图
but i get the error:
但是我得到了错误:
Failed to load resource: The requested URL was not found on this server.
未能加载资源:在此服务器上未找到请求的URL。
I read about this bug, is that the problem?
我读到过这个错误,是这个问题吗?
Also, on iOS 8, the location of the www folder is a bit different from iOS 7, it resolves to:
此外,在ios8上,www文件夹的位置与ios7略有不同,它决定:
file:///var/mobile/Containers/Data/Application/<UUID>/MYApp.app/www/views/add-project.html
文件:/ / / var /移动/集装箱/数据/应用程序/ < UUID > / / add-project.html MYApp.app / www /视图
Is this correct?
这是正确的吗?
I tried the toURL() and toInternalURL() methods to have the absolute paths like:
我尝试了toURL()和toInternalURL()方法来获得绝对路径:
cdvfile://localhost/root/var/mobile/Containers/Bundle/Application/<UUID>/MyApp.app/
but I get always the same error. Any suggestion?
cdvfile:/ / localhost /根/ var /移动/集装箱/包/应用/ < UUID > / MyApp。应用程序/但我总是犯同样的错误。任何建议吗?
Thanks
谢谢
3 个解决方案
#1
9
To whoever might find this useful, I finally manage to solve the problem.
不管谁觉得这有用,我终于设法解决了这个问题。
The full path to the www
folder on ios 8+ is:
ios8 +上www文件夹的完整路径是:
file:///private/var/mobile/Containers/Bundle/Application/<UUID>/<your_app>.app/www/
文件:/ / /私人/ var /移动/集装箱/包/应用程序/ < UUID > / < your_app > .app / www /
but when you request the application directory with Cordova, doing:
但是当你请求Cordova的应用程序目录时,
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory, onSuccess, onError);
window.resolveLocalFileSystemURL(cordova.file。applicationDirectory、调用onSuccess onError);
it will give you a wrong path (Cordova 3.7 on iOS 8.1.2) like:
它会给你一个错误的路径(Cordova 3.7在iOS 8.1.2):
file:////var/mobile/Containers/Bundle/Application/<UUID>/<your_app>.app/
文件:/ / / / var /移动/集装箱/包/应用程序/ < UUID > / < your_app > .app /
using the toURL() method suggested on the docs
使用在文档中建议的toURL()方法。
Therefore you need to manually do a bit of tweaking
因此,您需要手动进行一些调整。
var path = fileSystem.toURL();//given by the success callback
IOS_ASSETS_ABS_PATH = path.replace("file:////", "file:///private/");
IOS_ASSETS_ABS_PATH += "www/";
and bingo!
宾果!
#2
4
I ran into the same problem and I managed to solve it. In my case, my problem was that every time I update the app, the new app has a different id than the last one. For instance, the path for the older app was:
我遇到了同样的问题,我设法解决了它。在我的例子中,我的问题是每次我更新应用程序时,新应用程序的id都与上一个不同。例如,旧的应用程序的路径是:
file:///var/mobile/Containers/Data/Application/7A3590E8-C78A-4F45-B5B9-51FD0BAFE524/Library/files/file.pdf
And new one:
和新一:
file:///var/mobile/Containers/Data/Application/1BC5FS-7B3B-90E8-C7C8-1B7C1984C2A71/Library/files/file.pdf
So even though my pdf files were still on the application data storage, I was using the wrong path since the app created a new application id. I solved this by creating a new function that updates my path every time there is an update. I find the application id by using:
因此,即使我的pdf文件仍然在应用程序数据存储中,我还是使用了错误的路径,因为应用程序创建了一个新的应用程序id。我通过以下方式找到了应用id:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
function onFileSystemSuccess(fileSystem) {
// Do what you need here
}
The filesystem is an object contains the nativeURL inside the root.
文件系统是一个对象,包含根内的nativeURL。
Hope it helps!
希望它可以帮助!
#3
0
hit a similar problem, adding the WWW worked!
遇到类似的问题,添加WWW工作!
pic.style.backgroundImage = "url('../www/images/" + id + ".jpg')";
#1
9
To whoever might find this useful, I finally manage to solve the problem.
不管谁觉得这有用,我终于设法解决了这个问题。
The full path to the www
folder on ios 8+ is:
ios8 +上www文件夹的完整路径是:
file:///private/var/mobile/Containers/Bundle/Application/<UUID>/<your_app>.app/www/
文件:/ / /私人/ var /移动/集装箱/包/应用程序/ < UUID > / < your_app > .app / www /
but when you request the application directory with Cordova, doing:
但是当你请求Cordova的应用程序目录时,
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory, onSuccess, onError);
window.resolveLocalFileSystemURL(cordova.file。applicationDirectory、调用onSuccess onError);
it will give you a wrong path (Cordova 3.7 on iOS 8.1.2) like:
它会给你一个错误的路径(Cordova 3.7在iOS 8.1.2):
file:////var/mobile/Containers/Bundle/Application/<UUID>/<your_app>.app/
文件:/ / / / var /移动/集装箱/包/应用程序/ < UUID > / < your_app > .app /
using the toURL() method suggested on the docs
使用在文档中建议的toURL()方法。
Therefore you need to manually do a bit of tweaking
因此,您需要手动进行一些调整。
var path = fileSystem.toURL();//given by the success callback
IOS_ASSETS_ABS_PATH = path.replace("file:////", "file:///private/");
IOS_ASSETS_ABS_PATH += "www/";
and bingo!
宾果!
#2
4
I ran into the same problem and I managed to solve it. In my case, my problem was that every time I update the app, the new app has a different id than the last one. For instance, the path for the older app was:
我遇到了同样的问题,我设法解决了它。在我的例子中,我的问题是每次我更新应用程序时,新应用程序的id都与上一个不同。例如,旧的应用程序的路径是:
file:///var/mobile/Containers/Data/Application/7A3590E8-C78A-4F45-B5B9-51FD0BAFE524/Library/files/file.pdf
And new one:
和新一:
file:///var/mobile/Containers/Data/Application/1BC5FS-7B3B-90E8-C7C8-1B7C1984C2A71/Library/files/file.pdf
So even though my pdf files were still on the application data storage, I was using the wrong path since the app created a new application id. I solved this by creating a new function that updates my path every time there is an update. I find the application id by using:
因此,即使我的pdf文件仍然在应用程序数据存储中,我还是使用了错误的路径,因为应用程序创建了一个新的应用程序id。我通过以下方式找到了应用id:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
function onFileSystemSuccess(fileSystem) {
// Do what you need here
}
The filesystem is an object contains the nativeURL inside the root.
文件系统是一个对象,包含根内的nativeURL。
Hope it helps!
希望它可以帮助!
#3
0
hit a similar problem, adding the WWW worked!
遇到类似的问题,添加WWW工作!
pic.style.backgroundImage = "url('../www/images/" + id + ".jpg')";