Skip to content

Conversation

DannyvanderJagt
Copy link
Contributor

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.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Aug 14, 2015
@ghost
Copy link

ghost commented Aug 15, 2015

❤️

@seidtgeist
Copy link

Thank you @DannyvanderJagt, this worked for me. Nitpicking: Indentation needs to be adjusted now that it's a statement?

@DannyvanderJagt
Copy link
Contributor Author

@ehd Glad it worked and you're right, I have fixed it.

@seidtgeist
Copy link

Thanks again :)

@bleonard
Copy link
Contributor

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.

@anthonywebb
Copy link

Man, really need this fix, no merge yet?

@DannyvanderJagt
Copy link
Contributor Author

@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.

@jacob-israel-turner
Copy link
Contributor

+1, could have used this fix. :)

@kexhest
Copy link
Contributor

kexhest commented Sep 28, 2015

+1

id notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}else{
Copy link
Contributor

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 ericvicenti self-assigned this Sep 28, 2015
@DannyvanderJagt
Copy link
Contributor Author

@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.

@ide
Copy link
Contributor

ide commented Sep 29, 2015

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.

@DannyvanderJagt
Copy link
Contributor Author

@ide I have cleaned up the branch and squashed the commits. I also have updated the code of this PR, it is now using app instead of [UIApplication sharedApplication].

@ericvicenti
Copy link
Contributor

@facebook-github-bot shipit

@jaygarcia
Copy link
Contributor

XD. Facebook github bot is stuck on stupid ;)

[app registerUserNotificationSettings:notificationSettings];
[app registerForRemoteNotifications];
#else
[app registerForRemoteNotificationTypes:types];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fifdkl

@facebook-github-bot
Copy link
Contributor

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.

@vjeux
Copy link
Contributor

vjeux commented Sep 29, 2015

Whoops, sorry for the spam :x We need to fix that edge case :)

@ericvicenti
Copy link
Contributor

This failed our internal tests due to the following:
screen shot 2015-09-29 at 5 08 48 pm

@frantic, any thoughts on why the OSS tests pass but the internal ones do not?

@DannyvanderJagt
Copy link
Contributor Author

@ericvicenti The OSS is giving a warning instead of an error and therefore it passes.

screen shot 2015-09-30 at 11 18 24

I have fixed the actual problem/error. The problem is actually that types need to be converted to enum UIUserNotificationType. To accomplish this we need to replace types with (NSUInteger)types.

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.
I would like to hear to hear what you think before I add this.

@ericvicenti
Copy link
Contributor

Looks great!

Small note: use the UIUserNotificationSettings type instead of id

@DannyvanderJagt
Copy link
Contributor Author

@ericvicenti Thanks for the note.
I have replaced id notificationSettings with UIUserNotificationSettings * notificationSettings.

I have squashed and rebased the PR.
Let me know if there is anything else I can do.

@ghost ghost closed this in 200b811 Oct 1, 2015
udfalkso pushed a commit to purposecampaigns/react-native that referenced this pull request Oct 7, 2015
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
philly-d pushed a commit to philly-d/react-native that referenced this pull request Oct 16, 2015
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
MattFoley pushed a commit to skillz/react-native that referenced this pull request Nov 9, 2015
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
Crash-- pushed a commit to Crash--/react-native that referenced this pull request Dec 24, 2015
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
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.