Uh oh!
There was an error while loading. Please reload this page.
Pushnotifications events and fix for AppDelegate - #1979
Conversation
facebook-github-bot
commented
Jul 13, 2015
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! |
facebook-github-bot
commented
Jul 13, 2015
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
sahrens
commented
Jul 14, 2015
Agreed we can make this much easier, but I'm not sure this is the right approach...would it be possible to use a category instead so we don't have to add anything to AppDelegate.m? Passing to @tadeuzagallo |
tadeuzagallo
commented
Jul 14, 2015
It used to be documented on the sources, but apparently it's gone... @sahrens a category wouldn't work because the class name may change. I think I'm okay with this, since it's only on the SampleApp, I think it's harmless, but /cc @nicklockwood to see what his thoughts on it. |
brentvatne
commented
Jul 15, 2015
This tripped us up as well, I think the main issue right now is just this one:
We could either add cc @mattmo |
DannyvanderJagt
commented
Jul 15, 2015
Good to hear some thoughts on this. The solution from @brentvatne makes it less tricky to get up and running and with some proper documentation then it shouldn't be a problem. However I do think that preventing the user from adding code would be the best solution for the user/developer but only if it can be done in a good way. What are your thoughts on this? The possible solution in this PR is based on the issues I mentioned, the conversation in #1019 and the comment from @nicklockwood#1019 (comment)
I think that the code changes from the PR are what he meant, but I'm not entirely sure. I would like to hear his thoughts on this. @sahrens We could extend AppDelegate. This way we don't have to add anything to AppDelegate.m. Whatever the solution will be I do think that it should not only be applied to the SampleApp but also to the standaard project template, as nick said, because most people will use this to start their projects. |
DannyvanderJagt
commented
Jul 24, 2015
Any updates or thoughts on this? |
bogdantmm92
commented
Jul 29, 2015
+1 |
jaygarcia
commented
Jul 29, 2015
Question: does this have anything to do with JSContext not executing while the phone is locked & screen is off? I ask because I've seen a relationship discussed between the two problems. |
DannyvanderJagt
commented
Jul 29, 2015
@jaygarcia Not that I know off. The @brentvatne@tadeuzagallo@sahrens At this point I think is smart to separate this PR to keep things moving. I would like to separate this PR into:
And clean this one up and leave this one open for discussing about the Appdelegate fix/documentation fix. Or is there a way I can help you guys with the documentation for this? Please let me know what you think or what I can do. |
jaygarcia
commented
Jul 29, 2015
Thanks @DannyvanderJagt, for the clarification :). I thought these might be separate issues, but wanted to be sure. |
eyaleizenberg
commented
Aug 11, 2015
@DannyvanderJagt Any updates on this? Would love to see this merged. Thanks! |
ghost
commented
Aug 11, 2015
👍 changing RCTPushNotificationManager.m 159 works for me! Thanks @DannyvanderJagt Would love to see this merged too |
DannyvanderJagt
commented
Aug 11, 2015
@eyaleizenberg There is a conversation about the changes that I made in Appdelete, but there is no clear answer from the collaborators. So I will split this PR into:
And I will leave this PR open and clean it up. @potsypantsy Thank you for confirming! |
ghost
commented
Aug 11, 2015
@DannyvanderJagt if you don't mind I created a PR with just the changes in RCTPushNotificationManager.m |
DannyvanderJagt
commented
Aug 11, 2015
@potsypantsy No problem! Thank you for helping :) |
eyaleizenberg
commented
Aug 12, 2015
@DannyvanderJagt Were you able to:
PushNotificationIOS.addEventListener('register',(value)=>{console.log(value)});PushNotificationIOS.requestPermissions();And indeed I get the prompt that the app is requesting permission but the eventListener never triggers and I don't know the device's token. If I run: PushNotificationIOS.checkPermissions((permissions)=>{console.log(permissions);});I can see that I do have the permission, but again, I don't know the device's token.
Thanks. |
eyaleizenberg
commented
Aug 13, 2015
@DannyvanderJagt By the way, when using your code, the following warning appears in xcode. |
DannyvanderJagt
commented
Aug 13, 2015
@eyaleizenberg In my fork I was able to get the device token using the I didn't know about the problems with Thank you for pointing this out! |
This will prevent the user from adding the code to the app delegate when they want to use the Pushnotifications.
DannyvanderJagt
commented
Aug 13, 2015
I updated the code for this pull request but I accidentally closed the PR by removing the last few commits in order to rebase. Is there a way I can reopen it. I have already push new code to this branch. @eyaleizenberg The
All those things have to be done the right way otherwise the I found it very difficult to get the certificates right without seeing any error messages from react-native or IOS. I will create a PR with an error event for the push notifications module in React native today. The error event will help you to get those things right. For the record: The question about |
This will prevent the user from adding the code to the app delegate when they want to use the Pushnotifications.
cyprusglobe
commented
Aug 13, 2015
@DannyvanderJagt I'm wondering if you could write a tutorial on how to get push notifications working step by step, i think this would clear alot of confusion. |
DannyvanderJagt
commented
Aug 14, 2015
@cyprusglobe That would be a great idea! Any suggestions on where I should post the tutorial? |
cyprusglobe
commented
Aug 14, 2015
maybe just a blog post or a https://medium.com/ post or a video tutorial. |
DannyvanderJagt
commented
Aug 18, 2015
I have written a tutorial about How to use Push Notifications in React-Native. It's a step by step tutorial and everything from adding the library to getting the right certificates is explained. I hope it helps to clear the confusion about push notifications in React-Native. Let me know if I missed something. I have also mentioned these two Pull Requests (#2332, #2336) in the tutorial. I think that these PRs are important to get push notifications stable and fully working in React-Native. @sahrens@tadeuzagallo@brentvatne@nicklockwood Can you help to get those PRs (#2332, #2336) merged? Pull notifications aren't working right now in IOS 8 and higher and the error event would be a big improved for the people how want to use/are using push notifications in React-Native. |
cyprusglobe
commented
Aug 18, 2015
Thanks @DannyvanderJagt |
Summary: **Problem** Using push notifications in IOS 8 will throw this error: `registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.` The problem is that the check is running on compile instead of runtime. **Solution** If have changed the compile if statement to a runtime if statement. The fix is tested on: IOS 7.1 and 8.* and everything is working now. This solution is also discussed in: #1613 and it was part of #1979. (is being separated to keep things moving) Please let me know what you think.Closes#2332 Reviewed By: @svcscm Differential Revision: D2490987 Pulled By: @ericvicenti
Summary: **Problem** Using push notifications in IOS 8 will throw this error: `registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.` The problem is that the check is running on compile instead of runtime. **Solution** If have changed the compile if statement to a runtime if statement. The fix is tested on: IOS 7.1 and 8.* and everything is working now. This solution is also discussed in: react#1613 and it was part of react#1979. (is being separated to keep things moving) Please let me know what you think.Closesreact#2332 Reviewed By: @svcscm Differential Revision: D2490987 Pulled By: @ericvicenti
Summary: **Problem** Using push notifications in IOS 8 will throw this error: `registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.` The problem is that the check is running on compile instead of runtime. **Solution** If have changed the compile if statement to a runtime if statement. The fix is tested on: IOS 7.1 and 8.* and everything is working now. This solution is also discussed in: react#1613 and it was part of react#1979. (is being separated to keep things moving) Please let me know what you think.Closesreact#2332 Reviewed By: @svcscm Differential Revision: D2490987 Pulled By: @ericvicenti
yogurt-island-331
commented
Oct 18, 2015
@DannyvanderJagt amazing blog post! Thank you so much! Just curious, was there a reason that the following code was not committed into the latest release? |
DannyvanderJagt
commented
Oct 19, 2015
@kevinzzz007 Thank you! That piece of code is part of this PR #2332 which is merged a few weeks ago. The fix is implemented in all the versions from now on (v0.13 and higher). If you use v0.13 and higher you should be fine, otherwise you still have to implement the bug fix yourself. Thank you for the information. I have updated the article! |
yogurt-island-331
commented
Oct 19, 2015
Ahh I see! Thanks for letting me know and the the bug fix, extremely On Monday, October 19, 2015, Danny van der Jagt notifications@github.com
Kevin Zhao | LinkedIn http://www.linkedin.com/in/kevinzhaouva | Personal |
Summary: **Problem** Using push notifications in IOS 8 will throw this error: `registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.` The problem is that the check is running on compile instead of runtime. **Solution** If have changed the compile if statement to a runtime if statement. The fix is tested on: IOS 7.1 and 8.* and everything is working now. This solution is also discussed in: react#1613 and it was part of react#1979. (is being separated to keep things moving) Please let me know what you think.Closesreact#2332 Reviewed By: @svcscm Differential Revision: D2490987 Pulled By: @ericvicenti
Summary: **Problem** Using push notifications in IOS 8 will throw this error: `registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.` The problem is that the check is running on compile instead of runtime. **Solution** If have changed the compile if statement to a runtime if statement. The fix is tested on: IOS 7.1 and 8.* and everything is working now. This solution is also discussed in: react#1613 and it was part of react#1979. (is being separated to keep things moving) Please let me know what you think.Closesreact#2332 Reviewed By: @svcscm Differential Revision: D2490987 Pulled By: @ericvicenti

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 (#1304, #1019) and that some people created a workaround. This PR should fix those issues including the issue (#1613) where some good folks and I disused this.
Issue 1:
At this point people should:
1) add
RCTPushNotificationto their project.2) add this header to their Header Search Paths:
$(SRCROOT)/node_modules/react-native/Libraries/**3) add this code to their AppDelegate.m:
Solution
I couldn't find any documentation about this issue so this should be added to this page.
But 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 4c0ba9e)
I have added the code (from above) to AppDelegate.m and created a check for
RCTPushNotification. With this check the code will only run whenRCTPushNotificationis available/added and projects withoutRCTPushNotificationwon't notice any changes. The only thing people have to do is to add the library and start usingPushNotificationIOSin JS.Issue 2:
Update: This is now a seperate PR: #2336
How 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!