Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

No return from offline on iOS #59

Closed
mattwoberts opened this issue Feb 12, 2016 · 38 comments
Closed

No return from offline on iOS #59

mattwoberts opened this issue Feb 12, 2016 · 38 comments
Assignees
Milestone

Comments

@mattwoberts
Copy link

We're building a mobile app using manifoldJS. On iOS, when we lose the network (e.g. airplane mode), and then re-connect, the app never returns from the offline status page.

Just to give you a bit more context, we're using these plugins:

cordova-plugin-crosswalk-webview 1.5.0 "Crosswalk WebView Engine"
cordova-plugin-device 1.1.0 "Device"
cordova-plugin-hostedwebapp 0.2.1 "HostedWebApp"
cordova-plugin-network-information 1.1.0 "Network Information"
cordova-plugin-splashscreen 3.0.0 "Splashscreen"
cordova-plugin-statusbar 2.1.0 "StatusBar"
cordova-plugin-whitelist 1.0.0 "Whitelist"
phonegap-plugin-push 1.4.4 "PushPlugin"

We have our own offline page. We're testing this on 2 separate iphones, an iphone 4 and 6, and see the same issue on both.

iOS version is latest: 9.2.1

The offline mode works fine on android.

Any ideas?

@mattwoberts
Copy link
Author

Wonder if it's related to this:

#25

@mattwoberts
Copy link
Author

Sorry to bump this, I was just wondering if anyone else has seen this - it seems pretty bad, since it renders the whole offline stuff as unusable.

I'll try removing cordova and re-building the app, see if that makes a difference.

@boyofgreen
Copy link
Contributor

Hi Matt, I'm looking at this now, sorry for the delay, we've been focused on 0.5 upcoming. So you are saying that the "online" event code doesn't seem to be working? it accurately goes offline, but never comes online.

@boyofgreen
Copy link
Contributor

Hi Matt,
I just tried a few apps in the iOS store that I know are using Manifoldjs and they all came right back online, are you seeing any errors in the console when you go back online?
Offline is handled with different code in iOS than it is with other platforms:
https://github.com/manifoldjs/ManifoldCordova/blob/a31b045317d0b63974141b7c9d21434343135dd5/src/ios/CDVHostedWebApp.m
so it could be a version issue or something.

@mattwoberts
Copy link
Author

That's weird. I'll try to generate a vanilla app and see if I can recreate.
I'll post an update t-row, cheers for taking a look!

On Tue, 16 Feb 2016 22:23 Jeff Burtoft [email protected] wrote:

Hi Matt,
I just tried a few apps in the iOS store that I know are using Manifoldjs
and they all came right back online, are you seeing any errors in the
console when you go back online?


Reply to this email directly or view it on GitHub
#59 (comment)
.

@mattwoberts
Copy link
Author

Hi,

So I finally got round to testing this.

I'm testing on a real iphone 4, which has wifi connection, but no data network (there is no sim card in the phone).

I've just generated a new manifoldjs app with this command:

manifoldjs http://www.bbc.co.uk -d bbcapp -p ios

The app generates fine. I build and launch on the device, and then disconnect from the usb cable. Here's what I observe:

When I load the app, and then go aeroplane mode, nothing happens until I click a link on the page, at which point I get the offline page (by design?)
When I have the offline screen displayed, and then turn aeroplane mode off, I never return back to the app - I remain stuck in the offline page. The ony way back is for me to force-quite the app and launch it again.

Here's some output from xcode which may or may not be of use :)

When I first go into aeroplane mode:
2016-02-22 09:20:46.747 WwwBbcCoUk[236:8539] Invalid callback id received by sendPluginResult
While in aeroplane mode, I try to click a link:

2016-02-22 09:21:08.159 WwwBbcCoUk[236:8539] Resetting plugins due to page load.
2016-02-22 09:21:08.161 WwwBbcCoUk[236:8539] Received a navigation start notification.
2016-02-22 09:21:08.192 WwwBbcCoUk[236:8539] Failed to load webpage with error: The Internet connection appears to be offline.
2016-02-22 09:21:08.197 WwwBbcCoUk[236:8539] Received a navigation failure notification. error: Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={NSErrorFailingURLStringKey=http://www.bbc.co.uk/news, NSErrorFailingURLKey=http://www.bbc.co.uk/news, NSLocalizedDescription=The Internet connection appears to be offline., NSUnderlyingError=0x15e2f8b0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=8, NSErrorFailingURLStringKey=http://www.bbc.co.uk/news, NSErrorFailingURLKey=http://www.bbc.co.uk/news, NSLocalizedDescription=The Internet connection appears to be offline., _kCFStreamErrorDomainKey=12}}}

And again, when I turn OFF aeroplane mode:

2016-02-22 09:23:06.817 WwwBbcCoUk[236:8539] Invalid callback id received by sendPluginResult

Finally, here's the version of the plugins I'm using:

Matts-MacBook-Pro:cordova:% cordova plugin list                             
cordova-plugin-hostedwebapp 0.2.1 "HostedWebApp"
cordova-plugin-network-information 1.2.0 "Network Information"
cordova-plugin-whitelist 1.0.0 "Whitelist"

Any ideas?

@mattwoberts
Copy link
Author

Can anyone else confirm these steps produce the same issues as me on a different iphone device - @boyofgreen ?

@boyofgreen
Copy link
Contributor

Hi Matt, I only have a simulator at this time. @DaveVoyles can you do a base app and test this for Matt. The offline page is suppose to go on by itself when network is lost, so I think there must be something up with network-information

@mattwoberts I'll try this with the new version tonight on simulator and see if I get the same issue.

@mattwoberts
Copy link
Author

Hi @boyofgreen. I just tried that app I generated above on the simulator (iphone 6), and it works perfectly.

I then tried the same app deployed to another real device. This time it was my wifes iphone 5s. This behaves in much the same way as I reported - aeroplane mode doesn't get picked up until you try to navigate somewhere, and once in offline mode you don't come back.

@mattwoberts
Copy link
Author

bump Anyone else seeing this?

@mattwoberts
Copy link
Author

More updates re: this. I've upgraded everything, so I'm on manifoldjs 0.5.0, but the issue remains.

Created a new app as before using this new manifoldjs. Works perfectly on the simulator, but on 3 different test devices, it doesn't work. I tried debugging the app, didn't get too far since i don't know 'owt about objective c, but all I can see is that this isn't being hit:

// Handles notifications from the network-information plugin and shows the offline page whenever
// network connectivity is lost. It restores the original view once the network is up again.
- (void)updateConnectivityStatus:(NSNotification*)notification
{

.. when you're on a real device, although it does get hit when you test on the sim.

:(

@mattwoberts
Copy link
Author

I'm going to work round this by disabling the offline support and instead using the notifications from cordova network-information - the javascript notification hooks provided by that plugin are working fine for me, but no events are firing for the offline support added to this plugin.

However, I'm confused why no-one else is reporting to see this issue.. @boyofgreen did you manage to test this on a real device?

Matt

@boyofgreen
Copy link
Contributor

I have not yet. This is an interesting one. Clearly there is a bug, but we should also just give you the ability to disable to offline page as a manifest value.

@DaveVoyles
Copy link

Did you have to add anything to your info.plist iOS file to get this to run?

If I wrap my own site (DaveVoyles.com) then try to run it through my iphone 6 with xCode, it throws an error about "App Transport Security policy requires the use of a secure connection". Thought this SO post would have helped, but no dice.

@boyofgreen
Copy link
Contributor

So with the latest version of iOS, it is https only by default, but you can go into your plist (I don't remember the value, but I remember it being evident) and allow for http. if you can't find it, I'll crack open an app I did it for and see what it was

@mattwoberts
Copy link
Author

I haven't edited this for my app, my site is https

@DaveVoyles
Copy link

@mattwoberts Got it working. I just plugged the phone in and out a bunch and it suddenly removed that error. shrug.

Steps taken:

  1. Created a new ManifoldApp from the ManifoldJS generator page
  2. Open project in xCode & Changed info.plist to allow for Arbitrary loads, to load my default page
  3. Manifold app loads www.DaveVoyles.com
  4. When I turn on airplane mode the page hides and the text "It looks like you are offline. Please reconnect to use this application" appears.

Is that the expected behavior?

@mattwoberts
Copy link
Author

Cheers. Yeah that's the expected behaviour. Does it come back when you turn aeroplane off?

So the only difference is that you edited your plist, which shouldn't be an issue for me since I'm HTTPS.

@boyofgreen
Copy link
Contributor

and he probably has a SIM card in his phone, maybe that is the difference?

@DaveVoyles
Copy link

No, it does not come back when I turn airplane mode off and reconnect to the internet.

Yes, I have a SIM in this phone as well.

@boyofgreen
Copy link
Contributor

Thanks Dave. Something must have changed under us. There are a number of iOS issues raised on the tracker . We need to make sure we have it implemented correctly, then raise an issue if need be.

@boyofgreen
Copy link
Contributor

@mattwoberts
Copy link
Author

Hi. I'm testing on both a phone with and without a sim card - same issue on
both.

That code you highlight never gets hit for me on iOS when I go
offline/online.. Weird eh.

On Wed, 2 Mar 2016 16:38 Jeff Burtoft, [email protected] wrote:

looks like the issue would be here:

https://github.com/manifoldjs/ManifoldCordova/blob/a31b045317d0b63974141b7c9d21434343135dd5/src/ios/CDVHostedWebApp.m#L346


Reply to this email directly or view it on GitHub
#59 (comment)
.

@boyofgreen
Copy link
Contributor

yea, I saw something about the event name changing, maybe we are listening to an old even name

@mattwoberts
Copy link
Author

If I knew anything at all about obj-c I'd take a closer look :) might have a nosey anyway

@DaveVoyles
Copy link

I'm in the same boat -- I don't know any obj-c.

I agree, looks like it's in the exact spot you mentioned above, but you said it's never hitting that breakpoint, right?

@f2bo
Copy link
Contributor

f2bo commented Mar 3, 2016

As you've already noted, it works in the simulator and I'm afraid I don't have a device right now to test this, but if you place a breakpoint in the following line of the Plugins/CDVReachability.m file, does it get hit when the network status changes?

https://github.com/apache/cordova-plugin-network-information/blob/master/src/ios/CDVReachability.m#L103

@boyofgreen
Copy link
Contributor

@mattwoberts would you be able to try that? My guess is that it will run once, but not when it goes back online.

@mattwoberts
Copy link
Author

Yes, it's on my to-do list tonight - I'll get back to you in a couple of hours!

@mattwoberts
Copy link
Author

@boyofgreen @f2bo Hi - just tested, and a breakpoint on that line is never being hit for me - the javascript offline / offline code is firing for me, but never that breakpoint, not even first load.

@f2bo
Copy link
Contributor

f2bo commented Mar 5, 2016

Hi @mattwoberts.

Interesting. I mentioned placing the breakpoint in the line that actually posts the notification, but just to be sure, can you make sure that the CDVReachabilityCallback method doesn't get called at all? There's some validation code in that method that might cause it to skip the line with the breakpoint.

There's another breakpoint that you can set that might help to understand what is going on. Can you put a breakpoint in the sendPluginResult method?

https://github.com/apache/cordova-plugin-network-information/blob/3968f2069dfc858244640215046b09649d8b2eb4/src/ios/CDVConnection.m#L41

Assuming it gets hit, make a note of the call stack leading up to that breakpoint both when transitioning from online to offline and offline to online. (The call stack for all threads can be examined in the Debug navigator pane on the left side of Xcode).

Also, I'm intrigued by the fact that you say that the javascript offline / online code is working despite the fact that the notification on the native side never gets fired. Since I can't reproduce the problem in the simulator, I'm trying to understand the code path that needs to execute for that to happen. Presumably, you are hooking the online / offline events with code similar to the following, correct?

    document.addEventListener('deviceready',  function () {
        document.addEventListener("offline", function () {
            console.log('Device is OFFLINE...');
        }, false);
        document.addEventListener("online", function () {
            console.log('Device is ONLINE...');
        }, false);
    }, false);

@mattwoberts
Copy link
Author

Hi @f2bo

Right - here's my responses. I'm testing on an iphone 4 this time - it's the one that doesn't have a SIM card in it.

CDVReachabilityCallback - that method you asked me to breakpoint is not being hit at all. Ever. Just to be certain I wasn't doing something silly, I tested on a the simulator, and the breakpoints WERE hit without issue.

sendPluginResult:

Going from online to offline:

screen shot 2016-03-08 at 15 44 36

The stack looks the same going back again - am I looking for anything in particular?

Regarding the javascript API - yes absolutely, this is how I'm working around it for now. I listen to the events like this:

document.addEventListener("offline", offline, false); document.addEventListener("online", online, false);

And those functions fire perfectly, every time!

@boyofgreen
Copy link
Contributor

Thanks @mattwoberts , @f2bo and I will be together for the next few weeks and will have some real devices to test with, so we'll figure this out.

@boyofgreen boyofgreen self-assigned this Mar 10, 2016
@boyofgreen boyofgreen added this to the release-0.3 milestone Apr 13, 2016
@boyofgreen boyofgreen assigned f2bo and unassigned boyofgreen Apr 20, 2016
@mattwoberts
Copy link
Author

Hi. Just wondered if there was any update / progress on this. I've managed to work around it on my app, so it's not a major issue for me, but I'd ideally prefer to use this...

@boyofgreen
Copy link
Contributor

Hi Matt, we had to move it out of the 0.3 release (i know it's still tagged) since we didn't want to hold up the other changes with it. We have a 0.4 starting in two weeks, and we'll address it in that release, one way or another.
Sorry about the delay, but we haven't forgotten about you!

@estebanlopez estebanlopez modified the milestones: release-0.3, backlog Jun 6, 2016
@f2bo
Copy link
Contributor

f2bo commented Jun 9, 2016

Hi @mattwoberts,

Sorry it took so long to get back to you but we are currently working on the next release and have started looking at this issue again.

I can't tell whether I've been able to reproduce the same symptoms that you report. In my tests, the application does detect changes in network connectivity correctly on a device (iPhone 6s - iOS 9.3) when the application is in the foreground. However, I did find a problem when the changes happen while the application is in the background. I've pushed a potential fix to the ios-offline-fix branch. It would be very helpful if you can test it and let us know if you notice any improvement.

The only changed file is src/ios/CDVHostedWebApp.m, so it's probably easiest to test by replacing that file in a copy of your project.

Otherwise, you can replace the plugin with the one in the ios-offline-fix branch of this repo. For example:

cordova plugin rm cordova-plugin-hostedwebapp
cordova plugin add https://github.com/manifoldjs/ManifoldCordova.git#ios-offline-fix

@mattwoberts
Copy link
Author

👍

Excellent work - just got round to testing it, and it worked perfectly for me, on all real devices I could find hanging around.

Cheers - what release do you think this will be in?

@boyofgreen
Copy link
Contributor

we are targeting 0.6 for the end of the month, it will be in that one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants