AppHubPlatform / apphub

apphub is an iOS client for AppHub
https://apphub.io
Other
206 stars 29 forks source link

Add a way to force the app to update if the user never restarts their phone or exits the app #21

Open ExplodingCabbage opened 8 years ago

ExplodingCabbage commented 8 years ago

Currently, if the user never restarts the app, updated versions loaded from AppHub will never get run. Since certainly some people I know keep their iPhones on perpetually and never fully exit apps, this means they could be waiting a long time between updates.

My boss @TobyAbel recently raised this by email with @benthehenten asking whether there was any built-in way to deal with this problem (there isn't) and suggesting that otherwise we can roll our own logic to quit the app from the background so that it can update. Ben agreed we'd need to handle such a case manually. But I think there's actually a fair bit of nuance here and it would be good to hash out how to do this publicly and then - if it is indeed possible - to add a method to the library that implements this logic.

Interface-wise, I'm imagining being able to add something like

[AppHub restartAndLoadNewBuildWhenInactiveForMinutes: 60];

to my AppDelegate.m in order to have the app request background execution time to kill itself whenever there is a new build waiting to be run and it has been inactive for at least an hour.

This seems like it's probably pretty easy for somebody familiar with the native framework's API to bash out, but tricky for every React Native developer to need to roll themselves, which to my eyes justifies including it in the SDK. Thoughts?

Also, does anybody know whether doing this would even be allowed per Apple's rules? I've read contradictory things on the internet about the acceptability of calling exit(0). https://developer.apple.com/library/ios/qa/qa1561/_index.html is pretty explicit about it being a thing that should not be done, but I've read people claim to have successfully submitted apps to the app store that call it. Thoughts?

And if we can't implement killing the app from the background, what would be the nicest way to reinitialise the React Native part of it from the background instead, and can that similarly be nicely wrapped up in a method in this SDK?

arbesfeld commented 8 years ago

Hey @ExplodingCabbage, this is actually pretty simple to do with React Native! All you have to do is call [_bridge reload] after changing _bridge.bundleURL and React Native will automatically restart the app with a new bundle.

Here's an example AppDelegate.m that implements this behavior: https://github.com/AppHubPlatform/AppHubStarterProject/blob/master/iOS/AppHubStarterProject/AppDelegate.m

We should consider adding this feature directly the AppHub SDK, since it is commonly requested. I'll leave this issue open. If a few more people chime in, we should think through a way to add this to the library.

badams commented 7 years ago

@arbesfeld Is it possible to get the starter project updated?

I don't really know what I'm doing with Obj-c and that AppDelegate.m seems to be very out of date from the latest react-native version, so its a big struggle to get this working for me

rkotcher commented 7 years ago

@badams this actually still works. I'm currently using it in my project. What are you having trouble with?