Skip to content

Commit

Permalink
chore(docs): Updated readme for APNs installation (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
tahourj authored Apr 1, 2020
1 parent bf19cc1 commit c8c350d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,33 @@ react-native link @react-native-community/push-notification-ios

If you don't want to use the methods above, you can always [link the library manually](./docs/manual-linking.md).

### Update `AppDelegate.m`
### Add Capabilities : Background Mode - Remote Notifications

Go into your MyReactProject/ios dir and open MyProject.xcworkspace workspace.
Select the top project "MyProject" ans select the "Signing & Capabilities" tab.
Add a 2 new Capabilities using "+" button:
- `Background Mode` capability and tick `Remote Notifications`.
- `Push Notifications` capability


### Augment `AppDelegate`

Finally, to enable support for `notification` and `register` events you need to augment your AppDelegate.

### Update `AppDelegate.h`

At the top of the file:
```objective-c
#import <UserNotifications/UNUserNotificationCenter.h>
```

Then, add the 'UNUserNotificationCenterDelegate' to protocols:

```objective-c
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>
```
### Update `AppDelegate.m`
At the top of the file:
```objective-c
Expand Down

21 comments on commit c8c350d

@Psiiirus
Copy link
Contributor

Choose a reason for hiding this comment

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

@tahourj I'm going to update the example project and will do a PR if the example is working

@tahourj
Copy link
Contributor Author

@tahourj tahourj commented on c8c350d Apr 1, 2020

Choose a reason for hiding this comment

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

Feel free :) I'am wondering how did the implementation worked without adding capabilities as you get Warning/Error if you try to use Push Notification without capabilities ?

@Psiiirus
Copy link
Contributor

@Psiiirus Psiiirus commented on c8c350d Apr 1, 2020

Choose a reason for hiding this comment

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

@tahourj already added my PR but unf. this lib still doesn't work properly .... the onRegister event never gets triggered even the native call
[RCTSharedApplication() registerForRemoteNotifications]; will definitely executed. o.O

@tahourj
Copy link
Contributor Author

@tahourj tahourj commented on c8c350d Apr 1, 2020 via email

Choose a reason for hiding this comment

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

@tahourj
Copy link
Contributor Author

@tahourj tahourj commented on c8c350d Apr 1, 2020

Choose a reason for hiding this comment

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

On simulator you don't get event but error, for event you need real device :)

@Psiiirus
Copy link
Contributor

Choose a reason for hiding this comment

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

i know :) currently using an iPhone 11 with 13.4 and iPhone 7 with 13.1.3

@Psiiirus
Copy link
Contributor

@Psiiirus Psiiirus commented on c8c350d Apr 1, 2020

Choose a reason for hiding this comment

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

could you maybe check out my PR and run the example project? maybe i've missed something?!

@tahourj
Copy link
Contributor Author

@tahourj tahourj commented on c8c350d Apr 1, 2020

Choose a reason for hiding this comment

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

So implement :
1 - Request permissions to prompt persmission alert to user
PushNotificationIOS.requestPermissions();
2 - After permission you need to add register event to get token
PushNotificationIOS.addEventListener("register", (token) => { callback( token, null ) });
3- then don't forget error handling for simulator
PushNotificationIOS.addEventListener("registrationError", (error) => { callback( null, error ) // {message: string, code: number, details: any}. });

@Psiiirus
Copy link
Contributor

Choose a reason for hiding this comment

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

Bildschirmfoto 2020-04-01 um 15 26 45

non of this breakpoints ever get triggered

@tahourj
Copy link
Contributor Author

@tahourj tahourj commented on c8c350d Apr 1, 2020

Choose a reason for hiding this comment

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

Has I said getNotificationSettingsWithCompletionHandler need to be called on main thread.

@tahourj
Copy link
Contributor Author

@tahourj tahourj commented on c8c350d Apr 1, 2020

Choose a reason for hiding this comment

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

That's quite common issue on iOS.

@tahourj
Copy link
Contributor Author

@tahourj tahourj commented on c8c350d Apr 1, 2020

Choose a reason for hiding this comment

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

do you know how to :
Just move all getNotificationSettingsWithCompletionHandler call inside the dispatch block that @kylekurz added

@Psiiirus
Copy link
Contributor

Choose a reason for hiding this comment

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

Bildschirmfoto 2020-04-01 um 15 38 27

like this? ...did not work either :/

@tahourj
Copy link
Contributor Author

@tahourj tahourj commented on c8c350d Apr 1, 2020 via email

Choose a reason for hiding this comment

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

@Psiiirus
Copy link
Contributor

Choose a reason for hiding this comment

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

Well yeah i can send u some Team viewer logins if you like... by email or twitter DM?

But just to be sure my example project form my PR is working on your maschine?

@tahourj
Copy link
Contributor Author

@tahourj tahourj commented on c8c350d Apr 1, 2020

Choose a reason for hiding this comment

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

No no it's not your project I did the main thread thing myself as the PR wasn't yet approved

@tahourj
Copy link
Contributor Author

@tahourj tahourj commented on c8c350d Apr 1, 2020

Choose a reason for hiding this comment

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

Send me your teamviewver credential

@Psiiirus
Copy link
Contributor

@Psiiirus Psiiirus commented on c8c350d Apr 1, 2020

Choose a reason for hiding this comment

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

@tahourj
Copy link
Contributor Author

@tahourj tahourj commented on c8c350d Apr 1, 2020 via email

Choose a reason for hiding this comment

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

@Psiiirus
Copy link
Contributor

Choose a reason for hiding this comment

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

mhh did u make any changes to my fork? ...thats all seems to be really really odd

@tahourj
Copy link
Contributor Author

@tahourj tahourj commented on c8c350d Apr 1, 2020 via email

Choose a reason for hiding this comment

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

Please sign in to comment.