Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

how to add this in real server #223

Closed
@johnzhu12

Description

@johnzhu12

I use this plugin in my ionic project,and here is the step i go through below:

  1. 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
1

i'm not an expert in objective-c,so when i dig in your source code,nothing be clearer.thanks

Activity

nikDemyankov

nikDemyankov commented on Sep 19, 2016

@nikDemyankov
Member

You should use cordova-hcp build instead of cordova-hcp server to generate new chcp.manifest and chcp.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:

  1. Make sure, that local-dev-addon plugin is not installed in the project.
  2. Set correct config-file url in the config.xml. And make sure, that it is accessible.
  3. Generate new chcp.json and chcp.manifest files by running cordova-hcp build in the root of your project.
  4. Run ionic build ios command to copy updated www folder into the native project.
  5. Upload your www folder on your production server.
  6. Run the app on emulator/device.

This way your application will be set to use production server with proper configs. For each new release:

  1. Change what is needed in the www folder.
  2. Run cordova-hcp build to generate new configs.
  3. Upload new configs and www folder on the production server.
  4. Restart iOS app: it should reload config from the server on the launch. If you want - you can control when to request updates via JS API.
johnzhu12

johnzhu12 commented on Sep 20, 2016

@johnzhu12
Author

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

1

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

johnzhu12 commented on Sep 20, 2016

@johnzhu12
Author

the generated chcp.json doesn't have content_url,either,i think i should manually add these,right?will have a try first.

nikDemyankov

nikDemyankov commented on Sep 20, 2016

@nikDemyankov
Member

the generated chcp.json doesn't have content_url

Yes, you need to create cordova-hcp.json file in your project's root folder. And set content_url in it. For example:

{
  "content_url": "https://mydomain.com/chcp.json"
}

When you run cordova-hcp build - CLI client will use that config as a default one and add content_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.

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.

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 in chcp.json config to now:

{
  "content_url": "https://mydomain.com/chcp.json",
  "update": "now",
  "release": "213123123"
}

This way you tell the plugin to install the update immediately after downloading it.

You can check the docs for more details.

johnzhu12

johnzhu12 commented on Sep 21, 2016

@johnzhu12
Author

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 .

1

johnzhu12

johnzhu12 commented on Sep 21, 2016

@johnzhu12
Author

strange thing,when I create a small cordova hello world project,the HCP works perfect ! but my own ionic project just not work.

johnzhu12

johnzhu12 commented on Sep 21, 2016

@johnzhu12
Author

1

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

johnzhu12 commented on Sep 21, 2016

@johnzhu12
Author

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

johnzhu12 commented on Sep 21, 2016

@johnzhu12
Author

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

nikDemyankov commented on Sep 21, 2016

@nikDemyankov
Member

Glad, that you found the problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @johnzhu12@nikDemyankov

        Issue actions

          how to add this in real server · Issue #223 · nordnet/cordova-hot-code-push