phonegap mobile apps and version control and updates - android

I have currently built an application using phone gap targeting the android and blackberry platforms.
I use a combination of Jquery mobile and Phonegap for my application, since both are open source frameworks and improvements as well as bug fixes keep happening I wanted to know what would be a good solution for alerting my users to update their application when I upgrade the above frameworks in my application.
One solution I had in mind is maintain a version numbering on my server for the apps, when the app is loaded on the users device we can make an ajax call to check for version update and then alert the user to upgrade their application.
Android market also has an auto update feature how does that work! How do I go about this what would be a good approach.

If you are planning to build "native", in this case localy installed apps. You don't have to worry about informing the user. As soon as you uplad the new versions to the Android market or App World the App market systems will let the users know automatically.
I think (in most cases) it is not necessary to let the user know about updates within the app. Some apps do that but I see it less often since it really does not make much sense.
But in case you want to build such a feature, I would store a version number somwhere in the code and make a server request eg. when the app starts which then compares the latest version number of your app stored on your server.
Eg.
Client:
$.ajax({
url: webservice_host + '&callback=?',
dataType: 'jsonp',
success: function (data) {
//data -> remote version
var local_version;
if (local_version < data ){
alert("There is a newer version available");
}
}
});
Server (php in this case):
<?php
print mysql_real_escape_string($_GET['callback']). '( 1.1 )';
?>
I didn't test the code for typos etc. But this should do the trick.

Related

How to autoupdate android app without playstore? Like Facebook app or any Contest app

How do apps update internally automatically without updating from playstore?
I mean the internal data of app is changed (via internet) without updating from playstore. For eg any Contest app, or Facebook app. Here the newsfeed is updated automatically.
What is the technical term for that?
Any tutorial on it?
If you would like to check if you app has updates (without interacting with Google Play), you'd have to poll a server (providing your current version) and let the server check if there is a newer version available. If that is the case, let the server respond with a changelog and an url to the newer version.
Luckily, there are libraries to do this:
AppUpdater. Android Library that checks for updates on your own server (or Google Play, Github, etc). Great documentation. This library notifies your apps' updates by showing a Material dialog, Snackbar or notification.
Android Auto Update. Chinese library, but should do the trick, one of the most popular libraries to do this, but this can be just because Google Play is not available in China.
AppUpdateChecker A simple non-Market way to keep your app updated.
All it requires to set up is a URL pointing to a JSON document describing your app's changes.
Auto Updater This project allows to automatically update a running APK application using a private update server (see apk-updater) instead of Google Play updater. Also comes with a server script.
SmartUpdates. Older library, but instructions in English and also provides a server script.
WVersionManager. Checks for updates, but actual update has to be downloaded from the Play Store.
Answer from Mdlc is about updating the app itself but not the content.
What initially asked is how to create an App with dynamic content such Facebook or any other newsfeed app.
Any kind of such apps has 2 parts:
Server
Client
Server stores the whole information you need and client make requests to that server and displays information.
Let's say server stores in DB one entry called News#1. Client requests list of news and get back array[News#1] as response and show one tile on screen. Then somebody creates new entry News#2. On next request to the server client will get array of 2 elements: array[News#1, News#2] and displays this dynamic content.
REST Api Client is what to start with.
https://github.com/bitstadium/HockeySDK-Android/blob/develop/hockeysdk/src/main/java/net/hockeyapp/android/tasks/DownloadFileTask.java#L194 has the perfect and still working implementation on opening a downloaded APK file...
private fun install(downloadedAPK: File, context: Context) {
val intent = Intent(Intent.ACTION_INSTALL_PACKAGE)
intent.setDataAndType(Uri.fromFile(downloadedAPK),
"application/vnd.android.package-archive")
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
var oldVmPolicy: StrictMode.VmPolicy? = null
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
oldVmPolicy = StrictMode.getVmPolicy()
val policy = StrictMode.VmPolicy.Builder()
.penaltyLog()
.build()
StrictMode.setVmPolicy(policy)
}
context.startActivity(intent)
if (oldVmPolicy != null) {
StrictMode.setVmPolicy(oldVmPolicy)
}
}
Also have a look on AppCenter (Former HockeyApp) in-app updates https://learn.microsoft.com/en-us/appcenter/distribution/inappupdates
Here is the alternate
https://developer.android.com/guide/app-bundle/in-app-updates#update_readiness
try this google library to update from the application
dependencies {
implementation 'com.google.android.play:core:1.5.0'
...}
You can try this library: implementation 'com.github.vermat516:HelperLibrary:1.0.1'
This is best from my view we only have to write is:
new UniversalHelper(this).updateApp();
Rest of the work will automatically done by the library
This is response how your app will look like[This]

Cordova / Phonegap: Live update codebase

We are using Cordova along with AngularJS for iOS and Android applications.
One big disadvantage of iOS are the long review times from Apple. In Google's Playstore, your app is available nearly immediately, or within a few hours. But Apple takes ages to review your app, even when it's only a small change.
So I was thinking, if there is a way to support some kind of live update.
That means, I could provide a ZIP file or something else with a new codebase, my app checks for updates and then installs the new files.
I've read something from appmobi, but are there any open source solutions?
cordova-app-loader is an easy to use plugin to update app files via 3 simple steps:
check() for a new manifest
download() files
update() your app!
It supports android and iOS
I don't know of any ready made solutions for that, but it should be easy enough to program something like this on your own.
Here are some points to get you started and to consider:
If you want to distribute updates via zip, you need a nativ plugin which handles the extraction
You might not be able to override files in the default location of your app (depending on OS). So, all files you want to update in the future have to sit in a folder your app has read/write access to (iOS: e.g. Library or Documents folder)
Now you simply need to download the zip-package, unpack the zip to your chosen directory, and restart/reload your app.
you will not be able to update native plugins!
Apple probably doesn't like that, since you are able to change the whole application without passing
their review process
I'm doing this inside my cordova app and haven't had any issues with ios app store review.
I'm using Jquery's ajax function to download both a javascript and a css file from a server that I can change without an app store approval and then I can inject those scripts once they downloaded on app startup.
I tried using the cordova File api and I'd then save the file locally, but offline support ins't the important to me at the moment and Jquery's ajax is much simpler.
Here is the jquery code I use. I have a bundle id that I use to detect if a new javascript file is available, otherwise jquery's ajax caches the previous requests to speed up download time.
This solution lets you have a subset of your code be dynamic. I still have a base set of code that is bundled with the app, along with native plugin js and native code which would need to go through the app store. But this atleast lets me push bug fixes without going through the app store.
Otherwise, I'd look at a solution like this: http://docs.build.phonegap.com/en_US/tools_hydration.md.html
function insertScript(version) {
var scriptUrl = "";
try {
// get javascript file...
scriptUrl = mobileWebServiceUrl + "/DynamicContent/Bundles/Scripts/dynamic";
scriptUrl += "_" + bundleVersion.replace(/\./g, "_") + ".js?v=" + version;
console.log("downloading script: " + scriptUrl);
// Allow user to set any option except for dataType, cache, and url
options = {
dataType: "script",
cache: true,
url: scriptUrl
};
// Use $.ajax() since it is more flexible than $.getScript
// Return the jqXHR object so we can chain callbacks
return $.ajax(options).success(function(response) {
console.log("insertScript success");
dynamicContentScriptLoaded = true;
});
} catch (e) {
//console.error(e);
ReportError("problem downloading javscript: " + scriptUrl);
}
}
function insertCSS(version) {
try {
// get css file...
var cssUrl = mobileWebServiceUrl + "/DynamicContent/Bundles/Css/dynamic";
cssUrl += "_" + bundleVersion.replace(/\./g, "_") + ".css?v=" + version;
console.log("downloading dynamic css: " + cssUrl);
$.ajax(cssUrl)
.success(function (response) {
console.log("successfully downloaded dynamic css");
var script = document.createElement("style");
script.type = "text/css";
script.innerHTML = response;
$('head link').each(function () {
if ($(this).attr('href').search('MobileFrame') > -1) {
$("#MobileFrameCSS").before(script);
}
});
dynamicContentCssLoaded = true;
// TODO: implement caching at a later date
//if (isPhoneGap())
// saveFile("DynamicStyles", response);
});
} catch (e) {
ReportError("problem downloading css");
}
}
Well, Adobe offers exactly that service in their Phonegap Build service. It's called Hydration.
The example shows using it with Android and iOS platforms, so I guess they made it compatible with the iOS Dev Program License Agreement.
If you are using Cordova, you probably will have to switch to the Phonegap CLI if you want to use their build cloud services, which is basically the same as Cordova's with some extra commands to upload to their cloud, etc.
I think there are some plugin like Splashscreen wich also have some minor changes (using <gap>for params into config.xml instead of <preference>). Again, if Hydration solves the problem for you, the changes are minor and you get a really nice feature.
I think the best choice would be to not try to do this with Phonegap, but rather identify your dynamic parts and implement these in Javascript.
Yes, I mean you should indeed use Javascript yourself without Phonegap, for example via JavaScriptBridge:
https://github.com/kishikawakatsumi/JavaScriptBridge
It may require more work initially to redesign your app into a "static" part (your PhoneGap app) and dynamic part (dynamic created views via JavascriptBirdge), and interacte seemlessly between them. But in my opinion, that will be ultimately the best software design.
However, also make sure you still meet Apples AppStore requirements.
The Meteor framework provides exactly this functionality when combined with PhoneGap. It's even sanctioned by Apple in the latest Developer Agreement. Here are some technical details and then some about Apple's view on it.
I think there is no such solution is available, but you can do it by programmatic way.you can update your cardova app by fetching files from server and updating it.
Check out CodePush from Microsoft. Works with Cordova and React Native.
Appears to be very similar to the "live update" feature from Ionic Cloud.
If you migrate to capacitor, the successor of Cordova there open source solution now.
Capacitor-updater, is the only alternative to ionic AppFlow.
The updater allows you to manage update by yourself, store your zip update where you want and use the download method.
How to start
npm install #capgo/capacitor-updater
npx cap sync
Then in your main JS, this is required to let the updater know the update is valid
import { CapacitorUpdater } from '#capgo/capacitor-updater'
CapacitorUpdater.notifyAppReady()
And lately after checking yourself the current version need update:
const version = await CapacitorUpdater.download({
url: 'https://github.com/Cap-go/demo-app/releases/download/0.0.4/dist.zip',
})
await CapacitorUpdater.set(version); // sets the new version, and reloads the app
After many request of people didn't want to do that themselves, I started Capgo a business to manage all the update process.
All is open source and can be replicate on your own as well.
Doing things for Capacitor is now my main activity, I produce open-source plugin as my main channel of Marketing, I'm solo founder and bootstrapped.
Hope my tool will help you !

Cordova app that doesn't use push notifications: "Missing push notification entitlement"

We've got a Cordova based iOS app that does not use push notifications. As of Cordova 3.5.0, each submission we have made to the app store results in an email informing us that our app includes API used to register with Apple's Push Notification Service, but doesn't have push notification entitlement.
The app has been accepted each time, as we don't actually use push notifications for anything. However, I would like to avoid triggering this warning in case Apple decides to change their policy as to whether these API references are acceptable.
We did not experience the issue with prior versions of Cordova, and have done no work in Objective-C ourselves. Is this a known issue with Cordova 3.5? Searching has yielded some folks with similar problems but I've only found solutions for people wanting to add push entitlements, (rather than figure out where the Push API is being referenced and remove it). I took a look at the Cordova issues ML, but didn't find anything there. Any other leads that folks are aware of would be appreciated!
Plugins used:
org.apache.cordova.console
org.apache.cordova.device
org.apache.cordova.file
org.apache.cordova.inappbrowser
org.apache.cordova.media
org.apache.cordova.network-information
org.apache.cordova.splashscreen
Relevant email snippet, specific info replaced with [ ]:
From: iTunes Store
Date: Wed, Sep 17, 2014 at 3:49 PM
Subject: iTunes Connect: Your app "[appName]" (Apple ID: [id]) has one or more issues
To: [developer]
Dear developer,
We have discovered one or more issues with your recent delivery for "[app]". Your delivery was successful, but you may wish to correct the following issues in your next delivery:
Missing Push Notification Entitlement - Your app appears to include API used to register with the Apple Push Notification service, but the app signature's entitlements do not include the "aps-environment" entitlement. If your app uses the Apple Push Notification service, make sure your App ID is enabled for Push Notification in the Provisioning Portal, and resubmit after signing your app with a Distribution provisioning profile that includes the "aps-environment" entitlement. See "Provisioning and Development" in the Local and Push Notification Programming Guide for more information. If your app does not use the Apple Push Notification service, no action is required. You may remove the API from future submissions to stop this warning. If you use a third-party framework, you may need to contact the developer for information on removing the API.
After you’ve corrected the issues, you can use Xcode or Application Loader to upload a new binary to iTunes Connect.
Regards,
The App Store team
HOW TO DO THIS VIA THE XCODE UI (6.1):
While commenting out the offending code in Classes\AppDelegate.m will get your app approved, you want to continue benefitting from future Cordova upgrades so the best way to do this is to turn on the DISABLE_PUSH_NOTIFICATIONS symbol during compilation so this bit of code gets left out.
I come from a C# background so I understand conditional compilation but I am new to XCode so I had to do a bit of research finding out how to define compilation symbols via the UI.
Turns out the magic words are 'Preprocessor Macro'. This is how the you can accomplish this graphically (note that this the way its done in XCode 6.1):
Hope this helps other people out there in same situation.
Krik is right ! I've found this API calls in /Classes/AppDelegate.m certainly generated by Cordova 3.5.
I din't tried it for the moment, but these lines can certainly be commented in xCode to avoid Apple's warnings.
- (void) application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// re-post ( broadcast )
NSString* token = [[[[deviceToken description]
stringByReplacingOccurrencesOfString: #"<" withString: #""]
stringByReplacingOccurrencesOfString: #">" withString: #""]
stringByReplacingOccurrencesOfString: #" " withString: #""];
[[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotification object:token];
}
- (void) application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
// re-post ( broadcast )
[[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotificationError object:error];
}
Have you had the Push Plugin installed at some point? Sounds like you have the respective Code somewhere in your application package. I'd do a project-wide search for the specific API calls e.g:
didRegisterForRemoteNotificationsWithDeviceToken
didFailToRegisterForRemoteNotificationsWithError
The dead code, files need to be removed.
Heres' the full documentation: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW2
As Charles Merriam points out, newer versions of cordova-ios make it easy to disable touching push notifications by setting the preprocesor flag DISABLE_PUSH_NOTIFICATIONS. (See bug history.)
You will need to cordova platform update ios, platform uninstall ios and platform install ios to get the new in AppDelegate.m. (Maybe there's a better way than blowing away the folder?)
I found a Cordova on_platform_add hook script that will edit project.pbxproj with that flag for you when you install the iOS platform. I needed to npm install xcode to get the hook script to work.
Both kirk and r121 are correct.
In more recent versions of Cordova, this offending code is now helpfully generated inside a wrapper of #ifndef DISABLE_PUSH_NOTIFICATIONS. All you need do is add-DISABLE_PUSH_NOTIFICATIONS to your compiler flags. That's set in target/Build Settings/Custom Compiler Flags/(both C and C++ release) for those building inside XCode.
In our build process, we have been blowing away and rebuilding the AppDelegate.m file a lot. The hack I use is:
sed -i "" -e "s/ifndef DISABLE_PUSH_NOTIFICATIONS/if 0/" build/cordova/platforms/ios/gThrive/Classes/AppDelegate.m
# That uses the os/x sed to not have push notifications in the app
which just makes the problem go away.

Sencha-Touch + PhoneGap application web-view reload issue

I am developing a Sencha-Touch + PhoneGap application for Android and I am facing an issue that the web-view gets reloaded if the app was minimized for a long time.
The same thing happened when we run any memory cleaner apps on the device(Like Android Assistant,Clean Master etc..)
There is a login functionality in my app.So if the memory is cleared, the user needs to re-login to the app and the data inside the app will also be lost.(Please note that the data is very important)
How to prevent reload on android web-view when the app comes to foreground?
Or please suggest an alternative solution for retaining the user data.
Please note that I am using cordova 2.3 and sencha touch 2.3
Thanks in advance.
I think you need a client side data storage solution. Sencha Touch offer two solutions that may help you with this issue.
localstorage - http://docs.sencha.com/touch/2.3.1/#!/api/Ext.data.proxy.LocalStorage
Specify a proxy on your store to use local storage
proxy: {
type: 'localstorage',
id : 'important-data'
}
sql storage - http://docs.sencha.com/touch/2.3.1/#!/api/Ext.data.proxy.Sql
Specify a proxy on your store.
proxy: {
type: "sql"
}
With either of the above solutions your data will be available client side independent of the webview being reloaded.

Basic Android Licensing Enquiry

I am going to be sending off press-kits to various reviewers in regards to my new Android game and I am wondering how I should go about sending them an APK they can test? The game is paid and licensed.
If I send them the licensed version of the game they won't be able to run it on their phones without buying it. However, if I send them an unlicensed version and someone leaks it then everyone will just be able to get my game for free. What should I do?
Your options are pretty much limited to:
a time limited (demo) version
sending them an unlocked version which displays some personal information about the reviewer, thus making it in the reviewer's interests to keep the APK to themselves
using a licensing server. ie the game checks against a server (on GAE or similar) to see if it is allowed to run
I'm sure there are other options - I'd be interested to hear them.
One thing that is sorely missing from the Android Market is the ability to give the app to people. I think this is possible on the iOS store - at least like this you'd be able to grant real licences to the reviewers.
Following on from the above answers. Here's what I do (plus a message on the splash screen with the name of the reviewer)
private void initNewGame() {
//do a date check and quit if necessary
if ( reviewMode ) {
if ( new GregorianCalendar().after(new GregorianCalendar(2011,3,1,0,0,0))) {
//quit
((Program)parentActivity).finish();
}
}
}
I would also be interested if anyone has other ways of doing this, it's a really good question.
Make a free demo version that expires or something like that?

Categories

Resources