{"id":23223050,"url":"https://github.com/dckt/codepush-demo","last_synced_at":"2025-08-30T04:08:27.848Z","repository":{"id":146972579,"uuid":"93402819","full_name":"DCKT/codepush-demo","owner":"DCKT","description":"CodePush demo","archived":false,"fork":false,"pushed_at":"2017-06-06T14:18:15.000Z","size":240,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-05T16:35:11.469Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DCKT.png","metadata":{"files":{"readme":"README-en.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-05T12:44:40.000Z","updated_at":"2017-06-05T12:45:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"412804e5-94c5-4eed-8ac4-6024652a070a","html_url":"https://github.com/DCKT/codepush-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DCKT/codepush-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCKT%2Fcodepush-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCKT%2Fcodepush-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCKT%2Fcodepush-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCKT%2Fcodepush-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DCKT","download_url":"https://codeload.github.com/DCKT/codepush-demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCKT%2Fcodepush-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272800967,"owners_count":24995185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-18T23:15:52.977Z","updated_at":"2025-08-30T04:08:27.842Z","avatar_url":"https://github.com/DCKT.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Code Push\n\nWhen you develop a mobile application with React Native, you will need to share it to your users by the store (AppStore or PlayStore).\n\nThen, when your app is available, you will obviously encounter a production bug. In this kind of situation, depends of the bug gravity, it could be better to do a rollback to the previous version of your application. However, actually, the AppStore and PlayStore don't let us to do this kind of things.\n\nIndeed, you will have to upload the previous build version of your app to do a rollback. And also wait for the update to be effective. As you know, this could take some hours for the PlayStore to some days for the AppStore.\n\nYou risk, in case of blocking bug, to frustrate all the next users of your app and generate bad notes and comments until the correct patch.\n\nHopfully, there is a solution to this problem who will let you to update your application **without passing by the store** who is  [CodePush](https://microsoft.github.io/code-push/).\n\n## CodePush, a service\n\nCodePush is a hosted service highlighted by Microsoft who offer to React Native \u0026 Cordova developers, the ability to deploy updates directly on their user's phones.\n\nIt works simply by a repo system, in which you will send your JavaScript build to the service who will make the link with the application who use the SDK.\n\n**Note :** CodePush only allow to update statics elements like HTML, CSS, JavaScript and pictures. If you edit a native module, you will have to send your app to the store.\n\n## Configure our application\n\nBefore setting up the SDK, we have to create a new application in CodePush. This will be done by the CLI tool in 3 steps :\n\n1 - install CodePush CLI\n```\nnpm i -g code-push-cli\n```\n\n2- register to CodePush (if you don't own one yet)\n```\ncode-push register\n```\n\n3- Create an application\n```\n// At the root of your app\ncode-push app add MyApp-android android react-native\ncode-push app add MyApp-ios ios react-native\n```\n\nYou will see that we have to create an app for each platform. This has the disavantage to make you deploy 2 times the same build but this will allow you to fix a bug on a specific platform.\n\nAt the end, you will have two pairs of deploy keys (Staging, Production).\nWe will need it later but you can retrieve them with this command :\n\n```\ncode-push deployment list MyApp-android -k\n```\n\n## Setup the SDK\n\nThe SDK write by Microsoft is very well maintened on [Github](https://github.com/Microsoft/react-native-code-push) and follow scrupulously each React Native update. You can retrieve the list of CodePush versions based on [React Native version](https://github.com/Microsoft/react-native-code-push#supported-react-native-platforms).\n\nTo begin, you need to install the module :\n```\nyarn add react-native-code-push\n```\n\nThis SDK use native modules, so you must link him to the application :\n```\nreact-native link react-native-code-push\n```\n\nI will ask you to give the production keys for Android and iOS. And then, you will be able to use the SDK in your application.\n\nTo use the SDK, it's very easy, you just need to use a \"Higher Order Component\" (HOC) on the root component of your application (`App.js` in the demo project).\n\n```javascript\nimport React from 'react'\nimport codePush from 'react-native-code-push'\n\nclass App extends React.Component {\n  ...\n}\n\nexport default codePush(App)\n```\n\nYour app can now be updated by CodePush ! When you don't specify options, by default, CodePush will check if there is an update at the starting of the application, and if finds one, download it in background to install them at the next restart of the app.\n\n#### Edit the check frequency\n\nOf course, you can edit the frequency at which it checks if there is an update and when to install it.\nFor it, you need to pass an object as a params like this :\n\n```javascript\nimport codePush, { CheckFrequency } from 'react-native-code-push'\n...\nexport default codePush({\n  checkFrequency: CheckFrequency.ON_APP_RESUME\n})(App)\n```\n\nThe SDK offer us 3 ways to check update presence :\n- `ON_APP_START` : only when the app processus start\n- `ON_APP_RESUME` : when the application will go outside background mode\n- `MANUAL` : disallow the automatic checking and wait the call of `codePush.sync()` method.\n\n#### Edit install mode\n\nBy default, CodePush will install the new bundle only at the application restart. It's possible for you to install the update immediatly after the download.\n```javascript\nimport codePush, { CheckFrequency, InstallMode } from 'react-native-code-push'\n...\nexport default codePush({\n  mandatoryInstallMode: InstallMode.IMMEDIATE\n})(App)\n```\n\nThe SDK offer us 3 ways to install the update :\n- `IMMEDIATE` : update and restart the app\n- `ON_NEXT_RESTART` : default behavior, install the update after app restart\n- `ON_NEXT_RESUME` : install the update when the app will go outside background mode\n\nNow our SDK is well configured in our application, we can right create our first release with the CodePush CLI tool :\n```\ncode-push release-react MyApp-android android\ncode-push release-react MyApp-ios ios\n```\n\nTo that, it's possible to add very interesting options :\n- a description\n- the version from which the update can be installed\n- the environment, who is by default on `Staging`\n\n```\ncode-push release-react MyApp-ios ios -d Production --targetBinaryVersion '~1.0.0' -m --description \"Fix background\"\n```\n\nAnd voila ! Our first release is done !\n\n## Rollback\n\nLet us resume our case of the beginning, where we inconveniently released a bugged version of our app with CodePush. It's very fair to do a rollback on the previous version with the CLI : \n```\ncode-push rollback MyApp-ios Production\n```\n\nBy default, CodePush will take the previous version of the most recent, in the case you need to back further in your app history, you simply need to put the parameter `--targetRelease` with the label's name release (v2, v3, etc...).\n\n```\ncode-push rollback MyApp-ios Production --targetRelease v3\n```\n\n## Update manually\n\nIn some cases, you may need to offer to the user, the ability to check himself if there is an update.\nTo do that with CodePush, you have to give the parameter `updateDialog` to `true` or an object configuration. Here is an example : \n\n```javascript\nimport codePush, { CheckFrequency, InstallMode } from \"react-native-code-push\";\n\nclass App extends Component {\n  render() {\n    return (\n      \u003cView style={styles.container}\u003e\n        \u003cTouchableOpacity onPress={this._checkUpdates}\u003e\n          \u003cText\u003eCheck for updates\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n      \u003c/View\u003e\n    );\n  }\n\n  _checkUpdates() {\n    codePush.sync({\n      updateDialog: true,\n      installMode: InstallMode.IMMEDIATE\n    });\n  }\n}\n\nexport default codePush({\n  checkFrequency: CheckFrequency.MANUAL\n})(App);\n```\n\nWhen the update will be available and the user will press the button, he will get a native modal suggesting him to install the update.\n\n![Manual update](screenshots/manual_update.png)\n\nObviously, you can edit each text [via the params object](https://github.com/Microsoft/react-native-code-push/blob/master/docs/api-js.md#codepushoptions) `updateDialog`.\n\n**Note :** It's very important to know that this is **not allowed by the Apple guidelines** and they will not validate your app ! Howerver, you can do it on Android.\n\n## Conclusion\n\nCodePush has only advantages and is very easy to setup/configure. I can only recommand you to use it. You can retrive the different examples of this article on the [Github demo repo](https://github.com/DCKT/codepush-demo).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdckt%2Fcodepush-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdckt%2Fcodepush-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdckt%2Fcodepush-demo/lists"}