mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
Updates from Thu Mar 12
- Fixed sticky section headers in ListView | Nick Lockwood - [ReactNative] AppState cleanup, remove Subscribable, add in OSS examples | Eric Vicenti - [react-packager] package.json cleanup (seperate packager into it's own package) | Amjad Masad - [ReactNative] Move PushNotificationIOS to oss | Tadeu Zagallo - [ReactNative] Fix shake gesture after RedBox is dismissed | Alex Kotliarskyi - [catlyst|madman] fix prop type warning | Jiajie Zhu - [ReactNative] Remove Subscribable from TextInput | Eric Vicenti - Unforked ExceptionsManager, AlertManager and AppState | Nick Lockwood - [ReactNative|MAdMan] Notification Subscribable | Eric Vicenti - [ReactNative] OSS AsyncStorage with example | Spencer Ahrens
This commit is contained in:
74
Libraries/Utilities/PushNotificationIOS.js
Normal file
74
Libraries/Utilities/PushNotificationIOS.js
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
*
|
||||
* @providesModule PushNotificationIOS
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
||||
|
||||
var _notifHandlers = {};
|
||||
|
||||
var DEVICE_NOTIF_EVENT = 'remoteNotificationReceived';
|
||||
|
||||
class PushNotificationIOS {
|
||||
|
||||
static addEventListener(type, handler) {
|
||||
_notifHandlers[handler] = RCTDeviceEventEmitter.addListener(
|
||||
DEVICE_NOTIF_EVENT,
|
||||
(notifData) => {
|
||||
handler(new PushNotificationIOS(notifData));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
static removeEventListener(type, handler) {
|
||||
if (!_notifHandlers[handler]) {
|
||||
return;
|
||||
}
|
||||
_notifHandlers[handler].remove();
|
||||
_notifHandlers[handler] = null;
|
||||
}
|
||||
|
||||
constructor(nativeNotif) {
|
||||
this._data = {};
|
||||
|
||||
// Extract data from Apple's `aps` dict as defined:
|
||||
|
||||
// https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
|
||||
|
||||
Object.keys(nativeNotif).forEach((notifKey) => {
|
||||
var notifVal = nativeNotif[notifKey];
|
||||
if (notifKey === 'aps') {
|
||||
this._alert = notifVal.alert;
|
||||
this._sound = notifVal.sound;
|
||||
this._badgeCount = notifVal.badge;
|
||||
} else {
|
||||
this._data[notifKey] = notifVal;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getMessage() {
|
||||
// alias because "alert" is an ambiguous name
|
||||
return this._alert;
|
||||
}
|
||||
|
||||
getSound() {
|
||||
return this._sound;
|
||||
}
|
||||
|
||||
getAlert() {
|
||||
return this._alert;
|
||||
}
|
||||
|
||||
getBadgeCount() {
|
||||
return this._badgeCount;
|
||||
}
|
||||
|
||||
getData() {
|
||||
return this._data;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PushNotificationIOS;
|
||||
Reference in New Issue
Block a user