Cordova/Phonegap ios CORS perpetually loading - ios

I'm using xcode with an angular/ionic framework hybrid app for cordova. On my windows machine, I've been able to build and run for blackberry and android with this code successfully so I'm not sure what's not right. The back end is a Microsoft Web API restful service with basic windows authentication from active directory sending back JSON serialized data.
The main data call boils down to:
$http.get('http://192.168.0.12/api/values/1').
success(onSuccuess).
error(onFailure);
I'm sure I have the usual in the config and NSAllowsArbitraryLoads on the info.plist. I also have the most permissible "Content-Security_policy" meta tag on the main index.html file.
I'm fairly sure none of these are the issue because the loads will immediately fail in the safari development simulator dialog. My issue is that the load simply never finishes. If I double click the resource name in the "Network" tab, safari will open and load the data appropriately.
Again, this fails in the osx simulator and on a device hooked to the network. But works fine on my physical blackberry (Z10 lol) and android simulator on my windows machine.

Related

Cordova PWA application offline mode

I have made an angular + workbox application that now is converted using PWABuilder to Cordova project targeting ios platform.
Now my problem started with offline page, I want my application to work the same way it works on chrome browser with offline mode.
That is, even if I'm in offline mode, I'm able to use website and store the requests for later on.
But on IOS device, when I open application, then turn airplane mode or disconnect wifi and re-run an app a white screen appears. (Offline page support is disabled in manifest.js - I don't need Offline.html)
I have registered routing by
workbox.routing.registerNavigationRoute('/');
And then
// couple of following lines:
workbox.routing.registerRoute('regex with js,manifest...etc', networkFirstStrategy({cacheName} ...)
And the weird fact is that on ios this somehow can't be cached, or somethings different happens.
I'm waiting for any suggestions, or leads that can help me fix this behaviour.
Answer
The WebView as used by Cordova in the latest iOS (12.0.1) will not run Workbox because it doesn't support Service Workers.
Details
Cordova apps run in a WebView.
The app executes in a WebView within the native application wrapper... source
The WebView in the latest production iOS (12.0.1) only supports Service Workers within three specific contexts, which doesn't include Cordova apps.
At this time [the Service Worker API] is only available in Safari, applications that use SFSafariViewController, and web applications saved to your home screen. source
Next Steps
It may be possible to add Service Worker support via a Cordova Plugin. For example: cordova-plugin-service-worker.
In addition, you may also need to add Background Sync support as the latest Safari does not support Background Sync. For example: cordova-plugin-service-worker-background-sync.
The Workbox docs state that they provide a fallback strategy when Background Sync is not supported:
Workbox Background Sync...also implements a fallback strategy for browsers that
don't yet implement BackgroundSync. source
However, an open issue on Github shows that the fallback strategy may not work on iOS.

Issue with PWA on iOS 113

I have a PWA that I've been using perfectly till I updated my phone to 11.3 (introduce Service Workers supports, so in my iPhone it was only a bookmark) and all worked like a charm.
After I've updated to iOS 11.3 I wasn't able to enter to my app because I have an external login (in other domain) so each time I try to open my open this will open a safari browser to make the auth. Before PWA in iOS the external URLs were open in the same open (without open safari). Do you know if this is the correct behavior and, if it is ok, how can I fix it?
Thanks!
I managed to fix this by removing the manifest meta tag:
<link rel="manifest" href="/tracker/site.webmanifest">
My project is a simple PWA that uses Google's OAuth for login. I was getting redirected to Safari to login and unable to go back to the app (on my home screen). Hope it works for you too, I wasted 2 days trying to find a solution.
The reply by Anand tells me that offline capable PWAs need to implement service workers, since they are supported in 11.3 (or 11.4, not sure) and NOT manifests.
Anyways, this worked for me, hope it helps others as well.
When PWAs without service works(either your browser don't support it or your app don't have one) are added to home screen, its mere a bookmark. When the browser finds a SW, then it creates a package(like apk).
How to test this - Find a PWA site without service worker in android and add to home screen. When I tried it in one of Samsung device, it showed only "Remove" option and no uninstall option. When I added a PWA which had SW, got uninstall option. I was also able to locate the apk generated by Chrome when service worker is present.
Now on iOS - 3 possibilities I could think of.
1) My theory based on above behavior on PWAs with and without Service worker, your home icon create by iOS 11.2.x is a bookmark and the new version of safari is treating it as a bookmark to open it in browser. I couldn't test this as I've upgraded to 11.3 already and don't have a pre 11.3 PWA icon.
2) If you have reinstalled the icon(by removing and adding again to home screen) and still have the issue, its probably because your manifest file or service worker files have some issue/compatibility with Safari.
Since we don't have something like Lighthouse for safari, you can validate your manifest.json and service workers in Chrome Lighthouse.
3) Check on scope attribute in the manifest file to make sure you cover your entire domain you intent to cover. If you scope covers domain.com/myapp only, domain.com/otherapp will be opened in the browser when tried to open from any source.
It seems that with the last iOS version 11.4 this issue is solved, I think that now safari shares the context between the browser and the PWA and for example from PWA cookies can be accessed throw safari.
But I think there's still an issue when you open the PWA and you are being redirect to login (safari opens) once you're log in you stay in the browser (iOS does not return to the PWA, but this is a first step)

Access a Qlikview dashboard on an iOS app

I have a Qlikview dashboard that I need to present and I've created a site that loads the Qlikview server onto the browser and runs it from there.
I now need to create an iOS app that does this. But the requirement is that the dashboard shouldn't open on the browser. The server should be loaded and run from the app itself. Is there any way to do this?
PS, I'm completely new to iOS App development and any help will be appreciated.
Yes. While saving it as a shortcut and opening it in the browser would be simple, using Apache Cordova is the best way to develop a smartphone app with HTML5/CSS/JavaScript. From the website:
When using the Cordova APIs, an app can be built without any native
code (Java, Objective-C, etc) from the app developer. Instead, web
technologies are used, and they are hosted in the app itself locally
(generally not on a remote http server).
And to make things better, it's open source.

Do PhoneGap/Cordova Apps run under HTTP?

I'm coming behind another developer who built a PhoneGap/Cordova HTML 5 application, currently only targeting IOS. Admittedly, I have zero experience with Cordova and hybrid mobile apps.
I can open up the XCode IDE and run the application and I can see the web page (application) load up in the iPad emulator, so long as I have his Node.js application running.
I guess I'm confused about the context in which the actual index.html that makes up the HTML 5 application runs. Does it run on the iPad under a mini web server (http://local or http://localhost) or does the index.html run on a file system path (something like file://path-to-file/index.html)?
I've used Icenium (Telerik AppBuilder) and created an empty project for which I copied all the HTML 5 code into and ran it. Upon inspecting/debugging the page in the emulator, I see that the page is being served up with a base URL of http://local.
Lastly, I simply tried opening the index.html by double-clicking it and running it in the browser (file:///...builds/ios/www/index.html), and the application didn't work
In summary, as long as I run the website in an emulator, the application loads and runs file, but it won't run loading it from the file system.
My assumption is the scripts are expecting an http base URL and the file:/// url is throwing it off. Does this sounds like a reasonable explanation?
Do Cordova apps run the HTML 5 apps under HTTP?
Thank you.
they run on a file system path (something like file://path-to-file/index.html)
if you are using something from the phonegap API it won't work on a desktop browser

Do iPhone Offline Web Apps and Safari share the same HTML5 Application Cache?

I have a web app that is intended for use as an iOS offline web app. A key feature of the app is that users can download files with extensions like .doc, .ppt, .pdf, etc. To make these available offline, I am making entries for any such files in a cache manifest.
One other caveat: the most user-friendly way I could get these files to open is to jump out of the offline web app and into Safari to actually open the file. This way, I get the "Open in {{Application}}" options that Safari provides. There seems to be some sort of disconnect during this switch from the offline web app to Safari.
Assuming a clean slate:
I've gone and wiped all the data for this site using Settings->Safari->Advanced.
I launch the offline web app while connected to the server (So we're in online mode.)
The application updates the cache successfully.
I close the web app and disconnect from the server.
I relaunch the app and all of the navigation chrome works, so we know the cache is functioning properly.
I click the link to open a file that needs Safari, so iOS switches to Safari and goes to the file's URL.
Safari says "Safari cannot open the page because the server cannot be found."
So, it seems the this application cache is accessible from the offline web app, but not Safari? Can anyone verify this?
And then going forward, if that is in fact the case: any ideas for a better way to do it? Thanks!
iOS Safari work same as Safari does. But I assumed that your iOS Safari doesn't load successfully, you know, the network of iPhone isn't fast as your PC. You must attach handlers to determine when your offline data is loaded successfully.
Check it out: http://www.html5rocks.com/en/tutorials/appcache/beginner/ and try to use JS to check status of ApplicationCache.

Resources