how to add this in real server #223
Description
I use this plugin in my ionic project,and here is the step i go through below:
- add the follow node in my config.xml which is in my iOS platform
<chcp> <config-file url="http:/myserveraddress/www/chcp.json" /> </chcp>
change chcp.json file's content_url to http:/myserver/www, the chcp.json is in my www folder which is under the staging folder in Xcode.
3.cd to my project root folder from terminal ,run cordova-hcp server(when I change local file,it automatically change the corresponding hash value in chcp.manifest and release value in chcp.json)
4.copy the changed file ( et. index.html ), chcp.json, chcp.manifest to override the files on my server.
just days ago ,i make this work, after i override the files on server,and i reopen my app on iOS simulator, everything works fine ,after several seconds later ,the app page changed. but now it doesn't work.
i have some confusions,
1.did I really need to run cordova-hcp server command,if not, how can i automatically change the hash value
2. the following breakpoint not always hit when i rerun my app in Xcode
i'm not an expert in objective-c,so when i dig in your source code,nothing be clearer.thanks
Activity
nikDemyankov commentedon Sep 19, 2016
You should use
cordova-hcp build
instead ofcordova-hcp server
to generate newchcp.manifest
andchcp.json
files if you are using them for production.cordova-hcp server
should be used only for testing the app locally. Most likely, you will use it with local-dev-addon plugin.If you want to test your app with production server:
config-file
url in theconfig.xml
. And make sure, that it is accessible.chcp.json
andchcp.manifest
files by runningcordova-hcp build
in the root of your project.ionic build ios
command to copy updatedwww
folder into the native project.www
folder on your production server.This way your application will be set to use production server with proper configs. For each new release:
www
folder.cordova-hcp build
to generate new configs.www
folder on the production server.johnzhu12 commentedon Sep 20, 2016
sorry to bother you again,but i'm not clear about the next procedure, let's say i have gone through your steps and installed the app on sim,the index.html has text of 1111111111,as the pic shows below
my app's chcp.json is like this:
{
"autogenerated": true,
"release": "2016.09.20-10.14.45"
}
so ,now if I wanna update it again,I change my index's text to 22222222222,and run cordova-hcp build,now the local chcp.json looks like this:
{
"autogenerated": true,
"release": "2016.09.20-10.25.45"
}
so the release value is different now,right? I upload my chcp.json,chcp.manifest and my index.html, these 3 files to override them on server.when I close my app on sim and reopen it ,the page should change to 22222222 as i think,but it didn't,it still show the 111111111.
besides,the 'update' key-value is not here, this value is to control when to install the updates,right,should i added manually?
could you help me find any steps i did wrong,any tips would be nice,3ks.
johnzhu12 commentedon Sep 20, 2016
the generated chcp.json doesn't have content_url,either,i think i should manually add these,right?will have a try first.
nikDemyankov commentedon Sep 20, 2016
Yes, you need to create
cordova-hcp.json
file in your project's root folder. And setcontent_url
in it. For example:When you run
cordova-hcp build
- CLI client will use that config as a default one and addcontent_url
to the generated config.After that you can upload it on the server. Or you need to set it manually after CLI client generated configs. Otherwise it will not work: plugin would not know from where it should load files.
It depends on your configuration. First of all, "restart" means that you kill the app, not just go to home screen and back to app. Second, by default when the app is launched - plugin loads updates from the server, but not performing installation until the next launch. You can control that by setting the
update
flag inchcp.json
config tonow
:This way you tell the plugin to install the update immediately after downloading it.
You can check the docs for more details.
johnzhu12 commentedon Sep 21, 2016
I actually always killed the app ,then restart it,still not work,no matter I set the "update" to "now" or "start" . besides,I think maybe the content_url you mentioned up is mistaken. should be like "content_url": "https://mydomain.com/www",not with the "chcp.json" end .right?
it seems like I always need to delete the app on sim,and re-run from the Xcode, then the update is working .
johnzhu12 commentedon Sep 21, 2016
strange thing,when I create a small cordova hello world project,the HCP works perfect ! but my own ionic project just not work.
johnzhu12 commentedon Sep 21, 2016
the left pic is my own project,the right one is HCP working helloCordova which I created, I click the run button in Xcode,and check the log difference,the helloCordova printed "Nothing to update",so it did go to update,and my own project didn't,
I set the same config . going to check what's going wrong.
johnzhu12 commentedon Sep 21, 2016
I trace back the OC code and find the below func never call in my project but called in hello cordova.
`#pragma mark Methods, invoked from Javascript
(void)jsInitPlugin:(CDVInvokedUrlCommand *)command {
_defaultCallbackID = command.callbackId;
[self dispatchDefaultCallbackStoredResults];
if (_pluginXmlConfig.isUpdatesAutoDownloadAllowed &&
![HCPUpdateLoader sharedInstance].isDownloadInProgress &&
![HCPUpdateInstaller sharedInstance].isInstallationInProgress) {
[self _fetchUpdate:nil withOptions:nil];
}
}`
and this func leads to the
// check if new version is available if ([newAppConfig.contentConfig.releaseVersion isEqualToString:_oldAppConfig.contentConfig.releaseVersion]) {
area
johnzhu12 commentedon Sep 21, 2016
ok,have found the reason,I forgot to add cordova.js, which will call jsInitPlugin in OC from the chcp.js.
// Plugin methods on the native side that can be called from JavaScript pluginNativeMethod = { INITIALIZE: 'jsInitPlugin', FETCH_UPDATE: 'jsFetchUpdate', INSTALL_UPDATE: 'jsInstallUpdate', CONFIGURE: 'jsConfigure', REQUEST_APP_UPDATE: 'jsRequestAppUpdate', IS_UPDATE_AVAILABLE_FOR_INSTALLATION: 'jsIsUpdateAvailableForInstallation', GET_INFO: 'jsGetVersionInfo' };
thanks for the patience.will close this issue.
nikDemyankov commentedon Sep 21, 2016
Glad, that you found the problem :)