{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/react-native/issues/1979","labels_url":"https://api.github.com/repos/facebook/react-native/issues/1979/labels{/name}","comments_url":"https://api.github.com/repos/facebook/react-native/issues/1979/comments","events_url":"https://api.github.com/repos/facebook/react-native/issues/1979/events","html_url":"https://github.com/facebook/react-native/pull/1979","id":94795697,"number":1979,"title":"Pushnotifications events and fix for AppDelegate","user":{"login":"DannyvanderJagt","id":1556953,"avatar_url":"https://avatars.githubusercontent.com/u/1556953?v=3","gravatar_id":"","url":"https://api.github.com/users/DannyvanderJagt","html_url":"https://github.com/DannyvanderJagt","followers_url":"https://api.github.com/users/DannyvanderJagt/followers","following_url":"https://api.github.com/users/DannyvanderJagt/following{/other_user}","gists_url":"https://api.github.com/users/DannyvanderJagt/gists{/gist_id}","starred_url":"https://api.github.com/users/DannyvanderJagt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DannyvanderJagt/subscriptions","organizations_url":"https://api.github.com/users/DannyvanderJagt/orgs","repos_url":"https://api.github.com/users/DannyvanderJagt/repos","events_url":"https://api.github.com/users/DannyvanderJagt/events{/privacy}","received_events_url":"https://api.github.com/users/DannyvanderJagt/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/facebook/react-native/labels/CLA%20Signed","name":"CLA Signed","color":"e7e7e7"},{"url":"https://api.github.com/repos/facebook/react-native/labels/GH%20Review:%20review-needed","name":"GH Review: review-needed","color":"fbca04"}],"state":"closed","locked":false,"assignee":{"login":"tadeuzagallo","id":764414,"avatar_url":"https://avatars.githubusercontent.com/u/764414?v=3","gravatar_id":"","url":"https://api.github.com/users/tadeuzagallo","html_url":"https://github.com/tadeuzagallo","followers_url":"https://api.github.com/users/tadeuzagallo/followers","following_url":"https://api.github.com/users/tadeuzagallo/following{/other_user}","gists_url":"https://api.github.com/users/tadeuzagallo/gists{/gist_id}","starred_url":"https://api.github.com/users/tadeuzagallo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tadeuzagallo/subscriptions","organizations_url":"https://api.github.com/users/tadeuzagallo/orgs","repos_url":"https://api.github.com/users/tadeuzagallo/repos","events_url":"https://api.github.com/users/tadeuzagallo/events{/privacy}","received_events_url":"https://api.github.com/users/tadeuzagallo/received_events","type":"User","site_admin":false},"milestone":null,"comments":22,"created_at":"2015-07-13T19:42:39Z","updated_at":"2015-08-14T11:10:51Z","closed_at":"2015-08-13T13:09:30Z","pull_request":{"url":"https://api.github.com/repos/facebook/react-native/pulls/1979","html_url":"https://github.com/facebook/react-native/pull/1979","diff_url":"https://github.com/facebook/react-native/pull/1979.diff","patch_url":"https://github.com/facebook/react-native/pull/1979.patch"},"body":"There are a few problems with the push notifications in React-Native, which I discovered when I wanted to use push notifications for a project. I did some digging and I found out that there were some issues (https://github.com/facebook/react-native/pull/1304, https://github.com/facebook/react-native/pull/1019) and that some people created a workaround. This PR should fix those issues including the issue (https://github.com/facebook/react-native/issues/1613) where some good folks and I disused this.\r\n\r\n**Issue 1:**\r\n\r\n* Push notifications are working in React-Native but not out of the box. There are some things that people should add to their xcode project but there is nothing documented, besides adding the library.\r\n \r\nAt this point people should:\r\n**1)** add `RCTPushNotification` to their project.\r\n**2)** add this header to their Header Search Paths:  `$(SRCROOT)/node_modules/react-native/Libraries/**`\r\n**3)** add this code to their AppDelegate.m:\r\n\r\n```objective-c\r\n#import \"RCTPushNotificationManager.h\"\r\n\r\n- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken\r\n{\r\n    [RCTPushNotificationManager application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];\r\n}\r\n\r\n- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification\r\n{\r\n    [RCTPushNotificationManager application:application didReceiveRemoteNotification:notification];\r\n}\r\n```\r\n\r\n**Solution**\r\nI couldn't find any documentation about this issue so this should be added to [this](https://facebook.github.io/react-native/docs/pushnotificationios.html) page.\r\nBut I don't like it that people have to add a bunch of Objective-c code (Objective-c developers aren't the target audience here I think), so I did my best to create a good solution for this. (See 4c0ba9ea26883565e73a67c24d025229be51256b)\r\n\r\nI have added the code (from above) to AppDelegate.m and created a check for `RCTPushNotification`. With this check the code will only run when `RCTPushNotification` is available/added and projects without `RCTPushNotification` won't notice any changes. The only thing people have to do is to add the library and start using `PushNotificationIOS` in JS.\r\n\r\n**Issue 2:**\r\n**Update: This is now a seperate PR: https://github.com/facebook/react-native/pull/2336**\r\n\r\n>Push notifications doesn't have error handling and therefore all the errors that occur are silenced. Xcode doesn't show any errors and there is no error event in JS.  So when people use it and they didn't do everything right the first time they are left in the dark. \r\n\r\n>**Solution:**\r\nI have created an error event for javascript. This event will be fired when an error occurs in IOS and it will give you the error key and the error message straight from IOS. In IOS the error is an `NSError` which means that javascript gets it this way: `{key: message}`. I did separate the key and the message so that you can use the error event this way:\r\n\r\n>```js\r\nPushNotificationIOS.addEventListener('error', function(key, message){\r\n  console.log('error',  key,  message);\r\n  alert('error: ' + message);\r\n});\r\n```\r\n\r\nHow do you guys think about this? I would love the get your opinions/code reviews on this and to get this working in React-Native!"},"comment":{"url":"https://api.github.com/repos/facebook/react-native/issues/comments/131079319","html_url":"https://github.com/facebook/react-native/pull/1979#issuecomment-131079319","issue_url":"https://api.github.com/repos/facebook/react-native/issues/1979","id":131079319,"user":{"login":"DannyvanderJagt","id":1556953,"avatar_url":"https://avatars.githubusercontent.com/u/1556953?v=3","gravatar_id":"","url":"https://api.github.com/users/DannyvanderJagt","html_url":"https://github.com/DannyvanderJagt","followers_url":"https://api.github.com/users/DannyvanderJagt/followers","following_url":"https://api.github.com/users/DannyvanderJagt/following{/other_user}","gists_url":"https://api.github.com/users/DannyvanderJagt/gists{/gist_id}","starred_url":"https://api.github.com/users/DannyvanderJagt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DannyvanderJagt/subscriptions","organizations_url":"https://api.github.com/users/DannyvanderJagt/orgs","repos_url":"https://api.github.com/users/DannyvanderJagt/repos","events_url":"https://api.github.com/users/DannyvanderJagt/events{/privacy}","received_events_url":"https://api.github.com/users/DannyvanderJagt/received_events","type":"User","site_admin":false},"created_at":"2015-08-14T11:10:51Z","updated_at":"2015-08-14T11:10:51Z","body":"@cyprusglobe That would be a great idea! Any suggestions on where I should post the tutorial?"}}