Skip to content

Registering Push Notifications Twice #3288

@bleonard

Description

@bleonard
Contributor

I've been following #2332 and am glad that it looks like it will be in, but I still think there is an issue. I'm running iOS 8+

I'm seeing the push registration callback twice.

My appdelegate looks like this...

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
  [RCTPushNotificationManager application:application didRegisterUserNotificationSettings:notificationSettings];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
  [RCTPushNotificationManager application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
{
  [RCTPushNotificationManager application:application didReceiveRemoteNotification:notification];
}

The JS code ends up calling requestPermissions (RCTPushNotificationManager.m) which does

[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];

Then there is the appdelgate callback to didRegisterUserNotificationSettings and then didRegisterForRemoteNotificationsWithDeviceToken(both)

The first one calls back into RCTPushNotificationManager, which does this.

+ (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(__unused UIUserNotificationSettings *)notificationSettings
{
  [application registerForRemoteNotifications];
}

You'll note there is a second call to registerForRemoteNotifications

My iOS guy says he would remove the call to registerForRemoteNotifications in requestPermissions

Anyone else seeing this?

Activity

DannyvanderJagt

DannyvanderJagt commented on Oct 19, 2015

@DannyvanderJagt
Contributor

I have tried to replicate your problem but the register callback keeps firing once.

Which version of RN are you using?
If you did use v0.12 and lower did you apply the fix from #2332 ?

bleonard

bleonard commented on Dec 3, 2015

@bleonard
ContributorAuthor

I'll try it again in the more recent releases.

chirag04

chirag04 commented on Jan 8, 2016

@chirag04
Contributor

I'm also seeing this on 0.17.

registerPermissions calls

 [app registerUserNotificationSettings:notificationSettings];
 [app registerForRemoteNotifications];

[app registerForRemoteNotifications];

and didRegisterUserNotificationSettings also calls registerForRemoteNotifications

[[UIApplication sharedApplication] registerForRemoteNotifications];

cc @ericvicenti @nicklockwood

insraq

insraq commented on Feb 1, 2016

@insraq

I've tried this on RN 0.19 and can reproduce this issue.

yueshuaijie

yueshuaijie commented on Feb 2, 2016

@yueshuaijie

I use 0.19, have this problem, too.

my code:

  • (void)application:(UIApplication_)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData_)deviceToken
    {
    [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
    }
MichaelCereda

MichaelCereda commented on Feb 3, 2016

@MichaelCereda

i'm currently on 0.18 and i see this problem too, to avoid too many useless calls to my server i solved (not really) the issue adding a timeout+lock similar to this

   this.lock = false;
   ............
   ...........
   PushNotificationIOS.addEventListener('register', (token)=>{
      if(!this.lock){
        ....... sending token to server here .....
        this.lock = true;
        setTimeout(()=>{this.lock=false},1000*5); // 5 seconds
      }
    });
insraq

insraq commented on Feb 3, 2016

@insraq

@MichaelCereda You could just comment out the the call to registerForRemoteNotifications in requestPermission. That's way easier. Just patch RCTPushNotificationManager.m

[app registerForRemoteNotifications];

MichaelCereda

MichaelCereda commented on Feb 3, 2016

@MichaelCereda

thanks @insraq i just used this method because i don't want to patch react-native itself (and lose the changes in case of an update) :)
thank you anyways.

insraq

insraq commented on Feb 11, 2016

@insraq

Can we have a PR for this?

jacob-israel-turner

jacob-israel-turner commented on Feb 23, 2016

@jacob-israel-turner
Contributor

I'm having this same issue, a PR would be nice. Is the best solution to simply remove the registerForRemoteNotifications call in requestPermissions?

ghost added a commit that references this issue on Feb 24, 2016

1 remaining item

sgonyea

sgonyea commented on Apr 9, 2016

@sgonyea

The change that was merged in for this has actually broken push notifications in 0.23. I can't register for push unless I revert this change, in 0.23.

sgonyea

sgonyea commented on Apr 9, 2016

@sgonyea

The breaking change in question is: 5c41865

Granted, putting it back DOES invoke multiple calls. But that beats no calls :)

sgonyea

sgonyea commented on Apr 9, 2016

@sgonyea

The issue is basically that I can request to send push notifications (that works!) but I can't seem to get the Push Token via JS. So although the user's approved it, I can't send the token back to the server. 😢

insraq

insraq commented on Apr 13, 2016

@insraq

@sgonyea I've test 0.23 on my device. It works without any issue. Have you set up the event handlers in AppDelegate.m according to this page? https://facebook.github.io/react-native/docs/pushnotificationios.html

The code for event hook has changed as I recall. If you follow the old instruction, you might need to update your code.

tomazahlin

tomazahlin commented on Sep 1, 2016

@tomazahlin

Having the same issue, any news on this?

charpeni

charpeni commented on Nov 14, 2016

@charpeni
Contributor
charpeni

charpeni commented on Nov 14, 2016

@charpeni
Contributor

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/registering-push-notifications-twice

ProductPains helps the community prioritize the most important issues thanks to its voting feature.
It is easy to use - just login with GitHub.

Also, if this issue is a bug, please consider sending a PR with a fix.
We're a small team and rely on the community for bug fixes of issues that don't affect fb apps.

charpeni

charpeni commented on Nov 14, 2016

@charpeni
Contributor
facebook-github-bot

facebook-github-bot commented on Nov 14, 2016

@facebook-github-bot
Contributor

@charpeni tells me to close this issue. If you think it should still be opened let us know why.

locked as resolved and limited conversation to collaborators on Jul 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ran CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bleonard@sgonyea@MichaelCereda@insraq@chirag04

        Issue actions

          Registering Push Notifications Twice · Issue #3288 · facebook/react-native