Skip to content
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] Add error event #7694

Closed
wants to merge 2 commits into from
Closed

[Push notifications] Add error event #7694

wants to merge 2 commits into from

Conversation

DannyvanderJagt
Copy link
Contributor

This is PR is an updated version of: #2336 (closed)

This PR will add an error event to PushNotificationIOS.

How does this work?
The errors from didFailToRegisterForRemoteNotificationsWithError will be parsed to the error event in javascript.

Why is this useful?
At the moment PushNotificationIOS fails silently and there is no way of telling if something went wrong.
It would be very helpful to see the errors for debugging and in-app error handling.

How to use
The error event can be used just like the register and the notification events.
The error callback will give the original error object from IOS.

PushNotificationIOS.addEventListener('error', function(error){
  // Example: {NSLocalizedDescription: "REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION"}
   console.log('An error occurred: ', error);
});

To use the error event in javascript add these line to your AppDelegate.m:

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
  [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
}

PR
This is an new updated version of my 7 month closed old PR: #2336. I couldn't get the old branch updated without destroying the PR. I forked the master of react-native today and added back and updated all the code of the old PR.

TODO: Docs
This event should be added to the docs and the website. Can someone tell me how I can accomplish this?

TODO: Review
Objective-C is not a language I use often. It would be appreciated if someone could review this PR :)

@DannyvanderJagt
Copy link
Contributor Author

@satya164 Instead of re-oping the old PR (#2336) i created a new PR. I couldn't get the old branch updated without destroying the PR. I forked the master of react-native today and added back and updated all the code of the old PR.

@ghost
Copy link

ghost commented May 23, 2016

By analyzing the blame information on this pull request, we identified @slycoder and @nicklockwood to be potential reviewers.

@ghost ghost 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 May 23, 2016
- (void)handleRemoteNotificationRegisteredError:(NSNotification *)notification
{
[_bridge.eventDispatcher sendDeviceEventWithName:@"remoteNotificationsRegisteredError"
body:[notification userInfo]];
Copy link
Contributor

Choose a reason for hiding this comment

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

Judging by the preceding notification handlers, dot-notation is preferred: notification.userInfo.

@alloy
Copy link
Contributor

alloy commented May 23, 2016

@DannyvanderJagt Did a bit of review, otherwise it looks good to me. Hope it helps.

@DannyvanderJagt
Copy link
Contributor Author

@alloy Thank you! I will update the PR in a few minutes.

@alloy
Copy link
Contributor

alloy commented May 23, 2016

@nicklockwood Code-wise this seems good to me 👍

@ghost
Copy link

ghost commented May 23, 2016

@DannyvanderJagt updated the pull request.

@JAStanton
Copy link
Contributor

Hey, just noticed this still hasn't landed yet. Is there anything that I can do to help push this PR along?

@DannyvanderJagt
Copy link
Contributor Author

We are waiting for a review from a contributor I believe. I think that there are busy :)

@nicklockwood
Copy link
Contributor

I think this will need some rebasing due to the event emitter changes, but I'll see what I can do.

@nicklockwood
Copy link
Contributor

@facebook-github-bot shipit

@DannyvanderJagt
Copy link
Contributor Author

@nicklockwood Thank you! Let me know if there is anything i can do.

@@ -135,6 +140,15 @@ + (void)didReceiveLocalNotification:(UILocalNotification *)notification
userInfo:details];
}



+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
Copy link
Member

Choose a reason for hiding this comment

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

Can you the update the documentation in

* - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
to mention this method.

@ghost
Copy link

ghost commented Jun 22, 2016

It's been a while since the last commit was reviewed and the labels show this pull request needs review. Based on the blame information for the files in this pull request we identified @nicklockwood as a potential reviewer. Could you take a look please or cc someone with more context?

@nevir
Copy link
Contributor

nevir commented Jun 22, 2016

@DannyvanderJagt looks like this could use a rebase off of master; it has some conflicts w/ the new event emitter code

@DannyvanderJagt
Copy link
Contributor Author

@nevir @nicklockwood I will rebase this PR in the next few days.

@denisw
Copy link

denisw commented Aug 18, 2016

I see this pull request was closed. Is there a follow-up PR? If yes, it would be good to link to it from here.

@nevir
Copy link
Contributor

nevir commented Aug 29, 2016

Just opened an updated version of this PR via #9650

Note that it has a few differences, if you were previously depending on this patch:

  • The event is now registrationError
  • The error object itself now message (human readable string), code (number), and details (userInfo)

facebook-github-bot pushed a commit that referenced this pull request Sep 6, 2016
Summary:
This is an updated version of #2336 and #7694.

 ---

This adds a `registrationError` event that is emitted by `PushNotificationIOS` whenever an application receives a registration error from APNS (APNS service failure, running on simulator, etc).  This event fires to the exclusion of the `register` event (and vice versa).

**How to use**

Add the following to your `AppDelegate.m`:

```obj-c
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
  [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
}
```

And register an event handler for the event:

```js
PushNotificationIOS.addEventListener('registrationError', function({ message, code }) {
  // Complete your registration process in error.
});
```

**Test plan**

Added support for this event (and `register`) to UIExplorer as a proof of concept.  Navigating to the push notifications example on a simulator is an easy way to reproduce this e
Closes #9650

Differential Revision: D3822142

Pulled By: javache

fbshipit-source-id: a15ed8941b74dc3eed2c44c658deccbcaf39ce3d
mikelambert pushed a commit to mikelambert/react-native that referenced this pull request Sep 29, 2016
Summary:
This is an updated version of facebook#2336 and facebook#7694.

 ---

This adds a `registrationError` event that is emitted by `PushNotificationIOS` whenever an application receives a registration error from APNS (APNS service failure, running on simulator, etc).  This event fires to the exclusion of the `register` event (and vice versa).

**How to use**

Add the following to your `AppDelegate.m`:

```obj-c
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
  [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
}
```

And register an event handler for the event:

```js
PushNotificationIOS.addEventListener('registrationError', function({ message, code }) {
  // Complete your registration process in error.
});
```

**Test plan**

Added support for this event (and `register`) to UIExplorer as a proof of concept.  Navigating to the push notifications example on a simulator is an easy way to reproduce this e
Closes facebook#9650

Differential Revision: D3822142

Pulled By: javache

fbshipit-source-id: a15ed8941b74dc3eed2c44c658deccbcaf39ce3d
@DannyvanderJagt
Copy link
Contributor Author

@nevir Thank you for picking up this PR!

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.

7 participants