{"action":"created","comment":{"url":"https://api.github.com/repos/phonegap/phonegap-docs/pulls/comments/61136849","id":61136849,"diff_hunk":"@@ -2,7 +2,164 @@\n title: Push Notifications\n url: develop/push-notifications\n layout: subpage\n-write: false\n ---\n \n-Push Notifications content here\n+You can use the **PhoneGap Developer App** paired with the **PhoneGap CLI** to immediately preview your app on a device without installing platform SDKs, registering devices, or compiling code. The PhoneGap CLI starts a small web server to host your project and returns the server address for you to pair with from the PhoneGap Developer App running on your mobile device.\n+\n+As of **PhoneGap Developer App** release 1.6.2 and **PhoneGap CLI** release 6.2.0 you can now test push notification functionality without needing to setup a GCM project for Android or an Apple push certification for iOS.\n+\n+<div class=\"alert--warning\">Double check to ensure you're running your device and computer on the same network before continuing. </div>\n+\n+### Create Default PhoneGap Push Project\n+\n+1. Enter the following command from your terminal:\n+\n+\t\t$ phonegap create myApp --template phonegap-template-push\n+\n+   This will create a folder named myApp in the current path location with a default project name of Hello World and id of com.phonegap.helloworld.\n+\n+   You can also specify a name and identifier to ensure the project is unique but still contains the default Hello World code project by specifying them as qualified parameters as shown below:\n+\n+\t\t$ phonegap create myApp --id \"org.myapp.sample\" --name \"appSample\" --template phonegap-template-push\n+\n+2. Verify that you see the following output in your console after you run the command:\n+\n+\t\tCreating a new cordova project.\n+\n+3. Change into the new project directory with the cd command:\n+\n+\t\t$ cd myApp/\n+\n+4. Check to be sure you see the following set of files and folders shown below:\n+\n+\t\tconfig.xml      hooks        platforms    plugins        www\n+\n+5. `cd` into the ***www*** folder and look around at the files and subfolders in there, this is the content of your app, with the entry point being the index.html file.\n+\n+\t\t$ cd www/\n+\n+ <div class=\"alert--tip\">**TIP:** Details about the rest of the files and folders created in the root project  will be covered in guides further along. For now just focus on the ***www*** folder and its contents.</div>\n+\n+6. Type `$ phonegap serve`. You will receive the server address the app is being hosted on in the output received in the console (`192.168.1.11:3000` in this example):\n+\n+\t\t$ phonegap serve\n+\t\t[phonegap] starting app server...\n+\t\t[phonegap] listening on 192.168.1.11:3000\n+\t\t[phonegap]\n+\t\t[phonegap] ctrl-c to stop the server\n+\t\t[phonegap]\n+\n+7. Now go to your mobile device where the PhoneGap Developer App is running, enter the server address on the main screen and tap **Connect**.\n+\n+  <img class=\"mobile-image\" src=\"/images/dev-app-enter-add.png\" alt=\"PhoneGap Developer App, iOS\"/>\n+\n+\n+ <div class=\"alert--info\"> **NOTE:** Tap directly on the server address displayed in the terminal screen of the PhoneGap Developer app to change it to match yours. The value filled in by default is only a sample. </div>\n+\n+ You should see the connection occur followed by a success message as shown below. If you receive an error of any kind, ensure\n+ once again that you are connected to the same network on both your  and computer. You could also check the\n+ [issue tracker](https://github.com/phonegap/phonegap-app-developer/issues) and [PhoneGap Google Groups](https://groups.google.com/forum/#!forum/phonegap)\n+ list for further help.\n+\n+  <img class=\"mobile-image\" src=\"/images/dev-app-success.jpg\" alt=\"Developer App, connection success\"/>\n+\n+\n+ Once the PhoneGap Developer app connects and loads your mobile application, it should be displayed for preview as shown below:\n+\n+ <img class=\"mobile-image\" src=\"/images/dev-app-preview.jpg\" alt=\"Developer App, preview\"/>\n+\n+ The grey `Requesting Registration ID` line under the PhongGap Bot should turn into a green `Registered` line and you should see the following in your terminal session.\n+\n+     [phonegap] [console.log] registration event: APA91bE1MmeTc92igNoi5OkDWUV\n+\n+ <div class=\"alert--warning\">Obviously, your registration ID will be different but you get the picture.</div>\n+\n+### Sending Your First Push\n+\n+1. Open a new terminal window and enter the following command if you are testing on iOS:\n+\n+\t\t$ phonegap push --deviceID APA91bE1MmeTc92igNoi5OkDWUV --service apns --payload '{ \"aps\": { \"alert\": \"Hello World\" } }'\n+\n+   or enter the following command if you are testing on Android:\n+\n+\t\t$ phonegap push --deviceID APA91bE1MmeTc92igNoi5OkDWUV --service gcm --payload '{ \"data\": { \"title\": \"Hello\", \"message\": \"World\"} }'\n+\n+   replacing the deviceID with the one you received from the registration event in the previous step.\n+\n+2. This will result in a push notification being received by the app.\n+\n+   <img class=\"mobile-image\" src=\"/images/dev-app-success.jpg\" alt=\"Developer App, connection success\"/>\n+\n+### Explaining Push\n+\n+Now open the **www/index.js** file and we'll take a deep dive into what is going on. All of the code required to register and receive push notifications is in the `onDeviceReady` function.\n+\n+#### Initialization\n+\n+First we need to initialize the push notification system. The `init` function sets up the communication path with the remote push service and requests a registration ID. You will need to do this each time your app starts. Don't worry about requesting a registration ID each time your app starts. The phonegap-plugin-push code is smart enough to use cached registration ID if available.\n+\n+\t\tvar push = PushNotification.init({\n+\t\t\t\t\"android\": {\n+\t\t\t\t\t\t\"senderID\": \"XXXXXXXX\"\n+\t\t\t\t},\n+\t\t\t\t\"ios\": {\n+\t\t\t\t\t\t\"sound\": true,\n+\t\t\t\t\t\t\"vibration\": true,\n+\t\t\t\t\t\t\"badge\": true\n+\t\t\t\t},\n+\t\t\t\t\"windows\": {}\n+\t\t});\n+\n+<div class=\"alert--info\"> **NOTE:** You may notice the `senderID` is set to *XXXXXXXX*. That is okay as the **PhoneGap Developer App** will intercept this request and use the correct value. When you build an app for yourself you will need to get a `senderID` when you setup a project with Google to use GCM. </div>\n+\n+#### Registration\n+\n+Next we'll setup an event handler for the `registration` event. Once the app has successfully registered with the remote push service our event handler will be called. The function is called with only one parameter which is a data object and the object only has one property the `registrationId` received from the remote push service.\n+\n+Then we'll get the value of the saved `registrationId` from `localStorage`. If the old registration ID does not match the newly received registration ID we need to do two things. First, save the new `registrationId` into `localStorage`. Second, and the implementation is left up to the user, send the registration ID to your push service. For the purpose of this guide that functionality is not needed.","path":"docs/2-tutorials/2-develop/6-push-notifications.html.md","position":120,"original_position":120,"commit_id":"f92c06425490ce4d258e2e64c3be57b5e61a5322","original_commit_id":"ffa6d6fcbe4e5a985e1e359b947dba8e87e05df4","user":{"login":"hollyschinsky","id":359935,"avatar_url":"https://avatars.githubusercontent.com/u/359935?v=3","gravatar_id":"","url":"https://api.github.com/users/hollyschinsky","html_url":"https://github.com/hollyschinsky","followers_url":"https://api.github.com/users/hollyschinsky/followers","following_url":"https://api.github.com/users/hollyschinsky/following{/other_user}","gists_url":"https://api.github.com/users/hollyschinsky/gists{/gist_id}","starred_url":"https://api.github.com/users/hollyschinsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hollyschinsky/subscriptions","organizations_url":"https://api.github.com/users/hollyschinsky/orgs","repos_url":"https://api.github.com/users/hollyschinsky/repos","events_url":"https://api.github.com/users/hollyschinsky/events{/privacy}","received_events_url":"https://api.github.com/users/hollyschinsky/received_events","type":"User","site_admin":false},"body":"Suggested edit:\r\n\r\n>Second, send the registration ID to your push service. \r\n\r\n**NOTE:** The implementation for this second step is left up to the user and not relevant for the purposes of this guide.","created_at":"2016-04-26T18:16:10Z","updated_at":"2016-04-26T18:16:10Z","html_url":"https://github.com/phonegap/phonegap-docs/pull/173#discussion_r61136849","pull_request_url":"https://api.github.com/repos/phonegap/phonegap-docs/pulls/173","_links":{"self":{"href":"https://api.github.com/repos/phonegap/phonegap-docs/pulls/comments/61136849"},"html":{"href":"https://github.com/phonegap/phonegap-docs/pull/173#discussion_r61136849"},"pull_request":{"href":"https://api.github.com/repos/phonegap/phonegap-docs/pulls/173"}}},"pull_request":{"url":"https://api.github.com/repos/phonegap/phonegap-docs/pulls/173","id":67758666,"html_url":"https://github.com/phonegap/phonegap-docs/pull/173","diff_url":"https://github.com/phonegap/phonegap-docs/pull/173.diff","patch_url":"https://github.com/phonegap/phonegap-docs/pull/173.patch","issue_url":"https://api.github.com/repos/phonegap/phonegap-docs/issues/173","number":173,"state":"open","locked":false,"title":"Add Push documentation","user":{"login":"macdonst","id":353180,"avatar_url":"https://avatars.githubusercontent.com/u/353180?v=3","gravatar_id":"","url":"https://api.github.com/users/macdonst","html_url":"https://github.com/macdonst","followers_url":"https://api.github.com/users/macdonst/followers","following_url":"https://api.github.com/users/macdonst/following{/other_user}","gists_url":"https://api.github.com/users/macdonst/gists{/gist_id}","starred_url":"https://api.github.com/users/macdonst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/macdonst/subscriptions","organizations_url":"https://api.github.com/users/macdonst/orgs","repos_url":"https://api.github.com/users/macdonst/repos","events_url":"https://api.github.com/users/macdonst/events{/privacy}","received_events_url":"https://api.github.com/users/macdonst/received_events","type":"User","site_admin":false},"body":"Putting this up for review now but I still need to take a few screen shots for the docs. Need to be on a network that actually allows you to use `phonegap serve`.","created_at":"2016-04-25T17:38:20Z","updated_at":"2016-04-26T18:16:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7fa129d49960b463250916ba066659b995c7f614","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/phonegap/phonegap-docs/pulls/173/commits","review_comments_url":"https://api.github.com/repos/phonegap/phonegap-docs/pulls/173/comments","review_comment_url":"https://api.github.com/repos/phonegap/phonegap-docs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/phonegap/phonegap-docs/issues/173/comments","statuses_url":"https://api.github.com/repos/phonegap/phonegap-docs/statuses/f92c06425490ce4d258e2e64c3be57b5e61a5322","head":{"label":"phonegap:push","ref":"push","sha":"f92c06425490ce4d258e2e64c3be57b5e61a5322","user":{"login":"phonegap","id":60365,"avatar_url":"https://avatars.githubusercontent.com/u/60365?v=3","gravatar_id":"","url":"https://api.github.com/users/phonegap","html_url":"https://github.com/phonegap","followers_url":"https://api.github.com/users/phonegap/followers","following_url":"https://api.github.com/users/phonegap/following{/other_user}","gists_url":"https://api.github.com/users/phonegap/gists{/gist_id}","starred_url":"https://api.github.com/users/phonegap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phonegap/subscriptions","organizations_url":"https://api.github.com/users/phonegap/orgs","repos_url":"https://api.github.com/users/phonegap/repos","events_url":"https://api.github.com/users/phonegap/events{/privacy}","received_events_url":"https://api.github.com/users/phonegap/received_events","type":"Organization","site_admin":false},"repo":{"id":8228169,"name":"phonegap-docs","full_name":"phonegap/phonegap-docs","owner":{"login":"phonegap","id":60365,"avatar_url":"https://avatars.githubusercontent.com/u/60365?v=3","gravatar_id":"","url":"https://api.github.com/users/phonegap","html_url":"https://github.com/phonegap","followers_url":"https://api.github.com/users/phonegap/followers","following_url":"https://api.github.com/users/phonegap/following{/other_user}","gists_url":"https://api.github.com/users/phonegap/gists{/gist_id}","starred_url":"https://api.github.com/users/phonegap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phonegap/subscriptions","organizations_url":"https://api.github.com/users/phonegap/orgs","repos_url":"https://api.github.com/users/phonegap/repos","events_url":"https://api.github.com/users/phonegap/events{/privacy}","received_events_url":"https://api.github.com/users/phonegap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/phonegap/phonegap-docs","description":"PhoneGap Documentation","fork":false,"url":"https://api.github.com/repos/phonegap/phonegap-docs","forks_url":"https://api.github.com/repos/phonegap/phonegap-docs/forks","keys_url":"https://api.github.com/repos/phonegap/phonegap-docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/phonegap/phonegap-docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/phonegap/phonegap-docs/teams","hooks_url":"https://api.github.com/repos/phonegap/phonegap-docs/hooks","issue_events_url":"https://api.github.com/repos/phonegap/phonegap-docs/issues/events{/number}","events_url":"https://api.github.com/repos/phonegap/phonegap-docs/events","assignees_url":"https://api.github.com/repos/phonegap/phonegap-docs/assignees{/user}","branches_url":"https://api.github.com/repos/phonegap/phonegap-docs/branches{/branch}","tags_url":"https://api.github.com/repos/phonegap/phonegap-docs/tags","blobs_url":"https://api.github.com/repos/phonegap/phonegap-docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/phonegap/phonegap-docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/phonegap/phonegap-docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/phonegap/phonegap-docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/phonegap/phonegap-docs/statuses/{sha}","languages_url":"https://api.github.com/repos/phonegap/phonegap-docs/languages","stargazers_url":"https://api.github.com/repos/phonegap/phonegap-docs/stargazers","contributors_url":"https://api.github.com/repos/phonegap/phonegap-docs/contributors","subscribers_url":"https://api.github.com/repos/phonegap/phonegap-docs/subscribers","subscription_url":"https://api.github.com/repos/phonegap/phonegap-docs/subscription","commits_url":"https://api.github.com/repos/phonegap/phonegap-docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/phonegap/phonegap-docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/phonegap/phonegap-docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/phonegap/phonegap-docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/phonegap/phonegap-docs/contents/{+path}","compare_url":"https://api.github.com/repos/phonegap/phonegap-docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/phonegap/phonegap-docs/merges","archive_url":"https://api.github.com/repos/phonegap/phonegap-docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/phonegap/phonegap-docs/downloads","issues_url":"https://api.github.com/repos/phonegap/phonegap-docs/issues{/number}","pulls_url":"https://api.github.com/repos/phonegap/phonegap-docs/pulls{/number}","milestones_url":"https://api.github.com/repos/phonegap/phonegap-docs/milestones{/number}","notifications_url":"https://api.github.com/repos/phonegap/phonegap-docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/phonegap/phonegap-docs/labels{/name}","releases_url":"https://api.github.com/repos/phonegap/phonegap-docs/releases{/id}","deployments_url":"https://api.github.com/repos/phonegap/phonegap-docs/deployments","created_at":"2013-02-15T23:14:29Z","updated_at":"2016-04-26T05:56:22Z","pushed_at":"2016-04-26T14:09:38Z","git_url":"git://github.com/phonegap/phonegap-docs.git","ssh_url":"git@github.com:phonegap/phonegap-docs.git","clone_url":"https://github.com/phonegap/phonegap-docs.git","svn_url":"https://github.com/phonegap/phonegap-docs","homepage":"http://docs.phonegap.com","size":116829,"stargazers_count":76,"watchers_count":76,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":100,"mirror_url":null,"open_issues_count":20,"forks":100,"open_issues":20,"watchers":76,"default_branch":"master"}},"base":{"label":"phonegap:master","ref":"master","sha":"764fadc9fbe28a2b5067704979a68e043acead3e","user":{"login":"phonegap","id":60365,"avatar_url":"https://avatars.githubusercontent.com/u/60365?v=3","gravatar_id":"","url":"https://api.github.com/users/phonegap","html_url":"https://github.com/phonegap","followers_url":"https://api.github.com/users/phonegap/followers","following_url":"https://api.github.com/users/phonegap/following{/other_user}","gists_url":"https://api.github.com/users/phonegap/gists{/gist_id}","starred_url":"https://api.github.com/users/phonegap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phonegap/subscriptions","organizations_url":"https://api.github.com/users/phonegap/orgs","repos_url":"https://api.github.com/users/phonegap/repos","events_url":"https://api.github.com/users/phonegap/events{/privacy}","received_events_url":"https://api.github.com/users/phonegap/received_events","type":"Organization","site_admin":false},"repo":{"id":8228169,"name":"phonegap-docs","full_name":"phonegap/phonegap-docs","owner":{"login":"phonegap","id":60365,"avatar_url":"https://avatars.githubusercontent.com/u/60365?v=3","gravatar_id":"","url":"https://api.github.com/users/phonegap","html_url":"https://github.com/phonegap","followers_url":"https://api.github.com/users/phonegap/followers","following_url":"https://api.github.com/users/phonegap/following{/other_user}","gists_url":"https://api.github.com/users/phonegap/gists{/gist_id}","starred_url":"https://api.github.com/users/phonegap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phonegap/subscriptions","organizations_url":"https://api.github.com/users/phonegap/orgs","repos_url":"https://api.github.com/users/phonegap/repos","events_url":"https://api.github.com/users/phonegap/events{/privacy}","received_events_url":"https://api.github.com/users/phonegap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/phonegap/phonegap-docs","description":"PhoneGap Documentation","fork":false,"url":"https://api.github.com/repos/phonegap/phonegap-docs","forks_url":"https://api.github.com/repos/phonegap/phonegap-docs/forks","keys_url":"https://api.github.com/repos/phonegap/phonegap-docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/phonegap/phonegap-docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/phonegap/phonegap-docs/teams","hooks_url":"https://api.github.com/repos/phonegap/phonegap-docs/hooks","issue_events_url":"https://api.github.com/repos/phonegap/phonegap-docs/issues/events{/number}","events_url":"https://api.github.com/repos/phonegap/phonegap-docs/events","assignees_url":"https://api.github.com/repos/phonegap/phonegap-docs/assignees{/user}","branches_url":"https://api.github.com/repos/phonegap/phonegap-docs/branches{/branch}","tags_url":"https://api.github.com/repos/phonegap/phonegap-docs/tags","blobs_url":"https://api.github.com/repos/phonegap/phonegap-docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/phonegap/phonegap-docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/phonegap/phonegap-docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/phonegap/phonegap-docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/phonegap/phonegap-docs/statuses/{sha}","languages_url":"https://api.github.com/repos/phonegap/phonegap-docs/languages","stargazers_url":"https://api.github.com/repos/phonegap/phonegap-docs/stargazers","contributors_url":"https://api.github.com/repos/phonegap/phonegap-docs/contributors","subscribers_url":"https://api.github.com/repos/phonegap/phonegap-docs/subscribers","subscription_url":"https://api.github.com/repos/phonegap/phonegap-docs/subscription","commits_url":"https://api.github.com/repos/phonegap/phonegap-docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/phonegap/phonegap-docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/phonegap/phonegap-docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/phonegap/phonegap-docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/phonegap/phonegap-docs/contents/{+path}","compare_url":"https://api.github.com/repos/phonegap/phonegap-docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/phonegap/phonegap-docs/merges","archive_url":"https://api.github.com/repos/phonegap/phonegap-docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/phonegap/phonegap-docs/downloads","issues_url":"https://api.github.com/repos/phonegap/phonegap-docs/issues{/number}","pulls_url":"https://api.github.com/repos/phonegap/phonegap-docs/pulls{/number}","milestones_url":"https://api.github.com/repos/phonegap/phonegap-docs/milestones{/number}","notifications_url":"https://api.github.com/repos/phonegap/phonegap-docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/phonegap/phonegap-docs/labels{/name}","releases_url":"https://api.github.com/repos/phonegap/phonegap-docs/releases{/id}","deployments_url":"https://api.github.com/repos/phonegap/phonegap-docs/deployments","created_at":"2013-02-15T23:14:29Z","updated_at":"2016-04-26T05:56:22Z","pushed_at":"2016-04-26T14:09:38Z","git_url":"git://github.com/phonegap/phonegap-docs.git","ssh_url":"git@github.com:phonegap/phonegap-docs.git","clone_url":"https://github.com/phonegap/phonegap-docs.git","svn_url":"https://github.com/phonegap/phonegap-docs","homepage":"http://docs.phonegap.com","size":116829,"stargazers_count":76,"watchers_count":76,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":100,"mirror_url":null,"open_issues_count":20,"forks":100,"open_issues":20,"watchers":76,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/phonegap/phonegap-docs/pulls/173"},"html":{"href":"https://github.com/phonegap/phonegap-docs/pull/173"},"issue":{"href":"https://api.github.com/repos/phonegap/phonegap-docs/issues/173"},"comments":{"href":"https://api.github.com/repos/phonegap/phonegap-docs/issues/173/comments"},"review_comments":{"href":"https://api.github.com/repos/phonegap/phonegap-docs/pulls/173/comments"},"review_comment":{"href":"https://api.github.com/repos/phonegap/phonegap-docs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/phonegap/phonegap-docs/pulls/173/commits"},"statuses":{"href":"https://api.github.com/repos/phonegap/phonegap-docs/statuses/f92c06425490ce4d258e2e64c3be57b5e61a5322"}}}}