-
Notifications
You must be signed in to change notification settings - Fork 24.8k
[Push notifications] Fix for IOS 8 #2332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Push notifications] Fix for IOS 8 #2332
Conversation
❤️ |
Thank you @DannyvanderJagt, this worked for me. Nitpicking: Indentation needs to be adjusted now that it's a statement? |
@ehd Glad it worked and you're right, I have fixed it. |
Thanks again :) |
This is the fix that i was going to suggest for the issue i'm seeing as well. The issue is that the npm_module seems to define the deploy target itself as 7.0 so the #if will never work - a runtime check like in this PR is necessary. |
Man, really need this fix, no merge yet? |
@anthonywebb No merge yet, but this issue is easy to fix if you don't want to wait. I have also written a tutorial about How to use push notifications in React-Native for IOS, it also includes an explanation on how to fix this bug yourself. @nicklockwood @sahrens @brentvatne I know that you are very busy at the moment. However without this fix push notifications aren't working for IOS in React-Native. This fix is also discussed multiple times in the last few months (#1613, #1979, etc) and therefore it should be easy to review and merge this. Let me know if I can help you guys somehow. |
+1, could have used this fix. :) |
+1 |
id notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil]; | ||
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings]; | ||
[[UIApplication sharedApplication] registerForRemoteNotifications]; | ||
}else{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: spaces around else
@ericvicenti I have added the spaces. However when I did a rebase git added the 'Merge remote-tracking' commit. Let me know if that's a problem. |
Can you clean up your branch? Seems like something went wrong when you rebased. Also please squash your commits when you're ready for review. |
@ide I have cleaned up the branch and squashed the commits. I also have updated the code of this PR, it is now using |
@facebook-github-bot shipit |
XD. Facebook github bot is stuck on stupid ;) |
[app registerUserNotificationSettings:notificationSettings]; | ||
[app registerForRemoteNotifications]; | ||
#else | ||
[app registerForRemoteNotificationTypes:types]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fifdkl
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1056653971043101/int_phab to review. |
Whoops, sorry for the spam :x We need to fix that edge case :) |
This failed our internal tests due to the following: @frantic, any thoughts on why the OSS tests pass but the internal ones do not? |
@ericvicenti The OSS is giving a warning instead of an error and therefore it passes. I have fixed the actual problem/error. The problem is actually that The result will be: UIApplication *app = RCTSharedApplication();
if ([app respondsToSelector:@selector(registerUserNotificationSettings:)]) {
id notificationSettings = [UIUserNotificationSettings settingsForTypes:(NSUInteger)types categories:nil];
[app registerUserNotificationSettings:notificationSettings];
[app registerForRemoteNotifications];
} else {
[app registerForRemoteNotificationTypes:(NSUInteger)types];
} I've tested it and it works just as it should. |
Looks great! Small note: use the |
@ericvicenti Thanks for the note. I have squashed and rebased the PR. |
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: facebook#1613 and it was part of facebook#1979. (is being separated to keep things moving) Please let me know what you think.Closes facebook#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: facebook#1613 and it was part of facebook#1979. (is being separated to keep things moving) Please let me know what you think.Closes facebook#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: facebook#1613 and it was part of facebook#1979. (is being separated to keep things moving) Please let me know what you think.Closes facebook#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: facebook#1613 and it was part of facebook#1979. (is being separated to keep things moving) Please let me know what you think.Closes facebook#2332 Reviewed By: @svcscm Differential Revision: D2490987 Pulled By: @ericvicenti
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.