المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : انشاء صفحة خطا Cordova ErrorUrl موجهه الى صفحة 404 error - الكوردوفا و الفون جاب



Rise Company
26-07-2017, 21:00
انشاء صفحة خطا Cordova ErrorUrl موجهه الى صفحة 404 error - الكوردوفا و الفون جاب
الكوردوفا و الفون جاب Phone Gap / Cordova

عند حدوث خطا فى البرنامج او فى الروابط او انقطاع الانترنت سيسظهر الخطا بشكل غير مناسب

وقد يتعطل البرنامج عن العمل فالافضل عمل صفحة توجيه للايرور error page

متوافق مع الاندرويد فقط , ضع داخل ملف الكونفج config


<preference name="ErrorUrl" value="file:///android_asset/www/error.html" />

انتبه جيدا الكود الذى باللون الاحمر صحيح 100 % , غير فى الملف الى باللون الازرق

لازم يكون فى الرابط file و /// ولازم يكون هناك android_asset حتى وان كان لا يوجد فى الحقيقة

بعد وضع الكود فى الونفج اعمل ملف error.html داخل www

وستجد ان اى رابط غير صحيح اى لا يوجد ملف له داخل www سيخرج لك صفحة 404 الايرور

وهذه الصفحة ليس لها علاقة برسالة خطا انقطاع الانترنت عن الفيديو او الخريطة داخل التطبيق

وظيفة الكود هو اذا كان عندك خطا فى الروابط الداخلية تظهر صفحة 404

مع الانتباه ان تحويل الرابط الخطا الى صفحة 404 يظهر فقط من خلال تركيب التطبيق على الموبايل وليس من المتصفح

بدلا ما تظهر رسالة الاندرويد او غلق التطبيق بسبب crash

If set, will display the referenced page upon an error in the application instead of a dialog with the title "Application Error".


file:/// is a URI (Uniform Resource Identifier) that simply distinguishes from the standard URI that we all know of too well - http://.
It does imply an absolute path name pointing to the root directory in any environment, but in the context of Android, it's a convention to tell the Android run-time to say "Here, the directory www has a file called index.html located in the assets folder in the root of the project".
That is how assets are loaded at runtime, for example, a WebView widget would know exactly where to load the embedded resource file by specifying the file:/// URI.
Consider the code example:
WebView webViewer = (WebView) findViewById(R.id.webViewer);
webView.loadUrl("file:///android_asset/www/index.html"); A very easy mistake to make here is this, some would infer it to as file:///android_assets, notice the plural of assets in the URI and wonder why the embedded resource is not working!


تم التوضيح لان هناك كود قديم وهو سبب خطا ولا يعمل :


<preference name="ErrorUrl" value="myErrorPage.html"/>

احذر لا تستخدم هذا المسار فى الكود نهائيا فهو لن يعمل معك اطلاقا , فقط اتبع الكود فى اول الصفحة .


The docs say it should be located in file://android_asset/www/. So I made a file, error.html, and tried this:
<preference name=“errorUrl” value=“error.html” />
But that doesn’t work. You need to use a file-based URL. Maybe that’s assumed by the docs, but it wasn’t clear to me. This is what works:
<preference name=“errorUrl” value=“file:///android_asset/www/error.html” />
I mentioned to Simon that this setting seems a bit extreme. I mean, why would I link to and use the wrong URL, but certainly in a “real” application with some size in it this would be possible.


المرجع :

https://www.raymondcamden.com/2013/02/19/Some-examples-of-Android-PhoneGap-Config-Settings
https://stackoverflow.com/questions/11961975/what-does-file-android-asset-www-index-html-mean
https://cordova.apache.org/docs/en/1.5.0/guide/getting-started/android/