Expose content-available APS key for iOS silent push
Summary: <details> Thanks for submitting a PR! Please read these instructions carefully: - [ ] Explain the **motivation** for making this change. - [ ] Provide a **test plan** demonstrating that the code is solid. - [ ] Match the **code formatting** of the rest of the codebase. - [ ] Target the `master` branch, NOT a "stable" branch. Please read the [Contribution Guidelines](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md) to learn more about contributing to React Native. </details> _What existing problem does the pull request solve? In iOS when sending a silent push notification you need to configure the 'content-available' APS key to the value of 1 (When this key is present, the system wakes up your app in the background and delivers the notification to its app delegate, see [apple docs](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW1)). This PR exposes this property to the notification event handler so app code can handle silent push scenario specifically. Currently this property is not available. I've updated the PushNotificationIOSExample in the RNTester. 1. Open RNTester in xcode 2. Enable the push notifications capability 3. run on device 4. Go to PushNotificationIOS 5. click on "send fake notification" 6. verify alert message contains 'content-available' with a value of 1. Closes https://github.com/facebook/react-native/pull/14584 Differential Revision: D5279181 Pulled By: shergin fbshipit-source-id: d2288e147d89ba267f54265d819aa0a9969095e7
This commit is contained in:
parent
ebcf5fd241
commit
60783aa6ba
|
@ -24,6 +24,8 @@ const NOTIF_REGISTER_EVENT = 'remoteNotificationsRegistered';
|
|||
const NOTIF_REGISTRATION_ERROR_EVENT = 'remoteNotificationRegistrationError';
|
||||
const DEVICE_LOCAL_NOTIF_EVENT = 'localNotificationReceived';
|
||||
|
||||
export type ContentAvailable = 1 | null | void;
|
||||
|
||||
export type FetchResult = {
|
||||
NewData: string,
|
||||
NoData: string,
|
||||
|
@ -122,6 +124,7 @@ class PushNotificationIOS {
|
|||
_alert: string | Object;
|
||||
_sound: string;
|
||||
_category: string;
|
||||
_contentAvailable: ContentAvailable;
|
||||
_badgeCount: number;
|
||||
_notificationId: string;
|
||||
_isRemote: boolean;
|
||||
|
@ -419,6 +422,7 @@ class PushNotificationIOS {
|
|||
this._sound = notifVal.sound;
|
||||
this._badgeCount = notifVal.badge;
|
||||
this._category = notifVal.category;
|
||||
this._contentAvailable = notifVal['content-available'];
|
||||
} else {
|
||||
this._data[notifKey] = notifVal;
|
||||
}
|
||||
|
@ -484,6 +488,13 @@ class PushNotificationIOS {
|
|||
return this._alert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content-available number from the `aps` object
|
||||
*/
|
||||
getContentAvailable(): ContentAvailable {
|
||||
return this._contentAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the badge count number from the `aps` object
|
||||
*/
|
||||
|
|
|
@ -72,11 +72,13 @@ class NotificationExample extends React.Component {
|
|||
|
||||
_sendNotification() {
|
||||
require('RCTDeviceEventEmitter').emit('remoteNotificationReceived', {
|
||||
remote: true,
|
||||
aps: {
|
||||
alert: 'Sample notification',
|
||||
badge: '+1',
|
||||
sound: 'default',
|
||||
category: 'REACT_NATIVE'
|
||||
category: 'REACT_NATIVE',
|
||||
'content-available': 1,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -115,9 +117,15 @@ class NotificationExample extends React.Component {
|
|||
}
|
||||
|
||||
_onRemoteNotification(notification) {
|
||||
const result = `Message: ${notification.getMessage()};\n
|
||||
badge: ${notification.getBadgeCount()};\n
|
||||
sound: ${notification.getSound()};\n
|
||||
category: ${notification.getCategory()};\n
|
||||
content-available: ${notification.getContentAvailable()}.`;
|
||||
|
||||
AlertIOS.alert(
|
||||
'Push Notification Received',
|
||||
'Alert message: ' + notification.getMessage(),
|
||||
result,
|
||||
[{
|
||||
text: 'Dismiss',
|
||||
onPress: null,
|
||||
|
|
Loading…
Reference in New Issue