mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 12:45:37 +08:00
[ReactNative] Open Source PushNotifications and move Badge Number methods and permission into it
This commit is contained in:
@@ -1,67 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the BSD-style license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
|
||||||
*
|
|
||||||
* @flow
|
|
||||||
*/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var React = require('react-native');
|
|
||||||
var {
|
|
||||||
AppState,
|
|
||||||
StyleSheet,
|
|
||||||
Text,
|
|
||||||
TouchableHighlight,
|
|
||||||
View,
|
|
||||||
} = React;
|
|
||||||
|
|
||||||
var Button = React.createClass({
|
|
||||||
render: function() {
|
|
||||||
return (
|
|
||||||
<TouchableHighlight
|
|
||||||
underlayColor={'white'}
|
|
||||||
style={styles.button}
|
|
||||||
onPress={this.props.onPress}>
|
|
||||||
<Text style={styles.buttonLabel}>
|
|
||||||
{this.props.label}
|
|
||||||
</Text>
|
|
||||||
</TouchableHighlight>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var styles = StyleSheet.create({
|
|
||||||
button: {
|
|
||||||
padding: 10,
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
},
|
|
||||||
buttonLabel: {
|
|
||||||
color: 'blue',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
exports.title = 'AppState';
|
|
||||||
exports.description = 'App background status and badge value';
|
|
||||||
exports.examples = [
|
|
||||||
{
|
|
||||||
title: 'Set Badge Number',
|
|
||||||
render: function() {
|
|
||||||
return (
|
|
||||||
<View>
|
|
||||||
<Button
|
|
||||||
onPress={() => AppState.setApplicationIconBadgeNumber(42)}
|
|
||||||
label="Set app's icon badge to 42"
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
onPress={() => AppState.setApplicationIconBadgeNumber(0)}
|
|
||||||
label="Clear app's icon badge"
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}];
|
|
||||||
152
Examples/UIExplorer/PushNotificationIOSExample.js
Normal file
152
Examples/UIExplorer/PushNotificationIOSExample.js
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*
|
||||||
|
* @flow
|
||||||
|
*/
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var React = require('react-native');
|
||||||
|
var {
|
||||||
|
AlertIOS,
|
||||||
|
PushNotificationIOS,
|
||||||
|
StyleSheet,
|
||||||
|
Text,
|
||||||
|
TouchableHighlight,
|
||||||
|
View,
|
||||||
|
} = React;
|
||||||
|
|
||||||
|
var Button = React.createClass({
|
||||||
|
render: function() {
|
||||||
|
return (
|
||||||
|
<TouchableHighlight
|
||||||
|
underlayColor={'white'}
|
||||||
|
style={styles.button}
|
||||||
|
onPress={this.props.onPress}>
|
||||||
|
<Text style={styles.buttonLabel}>
|
||||||
|
{this.props.label}
|
||||||
|
</Text>
|
||||||
|
</TouchableHighlight>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
class NotificationExample extends React.Component {
|
||||||
|
componentWillMount() {
|
||||||
|
PushNotificationIOS.addEventListener('notification', this._onNotification);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
PushNotificationIOS.removeEventListener('notification', this._onNotification);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Button
|
||||||
|
onPress={this._sendNotification}
|
||||||
|
label="Send fake notification"
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_sendNotification() {
|
||||||
|
require('RCTDeviceEventEmitter').emit('remoteNotificationReceived', {
|
||||||
|
aps: {
|
||||||
|
alert: 'Sample notification',
|
||||||
|
badge: '+1',
|
||||||
|
sound: 'default',
|
||||||
|
category: 'REACT_NATIVE'
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_onNotification(notification) {
|
||||||
|
AlertIOS.alert(
|
||||||
|
'Notification Received',
|
||||||
|
`Alert message: ${notification.getMessage()}`,
|
||||||
|
[{
|
||||||
|
text: 'Dismiss',
|
||||||
|
onPress: null,
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NotificationPermissionExample extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {permissions: null};
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Button
|
||||||
|
onPress={this._showPermissions.bind(this)}
|
||||||
|
label="Show enabled permissions"
|
||||||
|
/>
|
||||||
|
<Text>
|
||||||
|
{JSON.stringify(this.state.permissions)}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_showPermissions() {
|
||||||
|
PushNotificationIOS.checkPermissions((permissions) => {
|
||||||
|
this.setState({permissions});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var styles = StyleSheet.create({
|
||||||
|
button: {
|
||||||
|
padding: 10,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
buttonLabel: {
|
||||||
|
color: 'blue',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
exports.title = 'PushNotificationIOS';
|
||||||
|
exports.description = 'Apple PushNotification and badge value';
|
||||||
|
exports.examples = [
|
||||||
|
{
|
||||||
|
title: 'Badge Number',
|
||||||
|
render(): React.Component {
|
||||||
|
PushNotificationIOS.requestPermissions();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Button
|
||||||
|
onPress={() => PushNotificationIOS.setApplicationIconBadgeNumber(42)}
|
||||||
|
label="Set app's icon badge to 42"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
onPress={() => PushNotificationIOS.setApplicationIconBadgeNumber(0)}
|
||||||
|
label="Clear app's icon badge"
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Push Notifications',
|
||||||
|
render(): React.Component {
|
||||||
|
return <NotificationExample />;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Notifications Permissions',
|
||||||
|
render(): React.Component {
|
||||||
|
return <NotificationPermissionExample />;
|
||||||
|
}
|
||||||
|
}];
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
|
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
|
||||||
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
|
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
|
||||||
147CED4C1AB3532B00DA3E4C /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 147CED4B1AB34F8C00DA3E4C /* libRCTActionSheet.a */; };
|
147CED4C1AB3532B00DA3E4C /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 147CED4B1AB34F8C00DA3E4C /* libRCTActionSheet.a */; };
|
||||||
|
14DC67F41AB71881001358AB /* libRCTPushNotification.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14DC67F11AB71876001358AB /* libRCTPushNotification.a */; };
|
||||||
D85B829E1AB6D5D7003F4FE2 /* libRCTVibration.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D85B829C1AB6D5CE003F4FE2 /* libRCTVibration.a */; };
|
D85B829E1AB6D5D7003F4FE2 /* libRCTVibration.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D85B829C1AB6D5CE003F4FE2 /* libRCTVibration.a */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
@@ -88,6 +89,13 @@
|
|||||||
remoteGlobalIDString = 134814201AA4EA6300B7C361;
|
remoteGlobalIDString = 134814201AA4EA6300B7C361;
|
||||||
remoteInfo = RCTActionSheet;
|
remoteInfo = RCTActionSheet;
|
||||||
};
|
};
|
||||||
|
14DC67F01AB71876001358AB /* PBXContainerItemProxy */ = {
|
||||||
|
isa = PBXContainerItemProxy;
|
||||||
|
containerPortal = 14DC67E71AB71876001358AB /* RCTPushNotification.xcodeproj */;
|
||||||
|
proxyType = 2;
|
||||||
|
remoteGlobalIDString = 134814201AA4EA6300B7C361;
|
||||||
|
remoteInfo = RCTPushNotification;
|
||||||
|
};
|
||||||
D85B829B1AB6D5CE003F4FE2 /* PBXContainerItemProxy */ = {
|
D85B829B1AB6D5CE003F4FE2 /* PBXContainerItemProxy */ = {
|
||||||
isa = PBXContainerItemProxy;
|
isa = PBXContainerItemProxy;
|
||||||
containerPortal = D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */;
|
containerPortal = D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */;
|
||||||
@@ -116,6 +124,7 @@
|
|||||||
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = UIExplorer/Images.xcassets; sourceTree = "<group>"; };
|
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = UIExplorer/Images.xcassets; sourceTree = "<group>"; };
|
||||||
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = UIExplorer/Info.plist; sourceTree = "<group>"; };
|
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = UIExplorer/Info.plist; sourceTree = "<group>"; };
|
||||||
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = UIExplorer/main.m; sourceTree = "<group>"; };
|
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = UIExplorer/main.m; sourceTree = "<group>"; };
|
||||||
|
14DC67E71AB71876001358AB /* RCTPushNotification.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTPushNotification.xcodeproj; path = ../../Libraries/PushNotificationIOS/RCTPushNotification.xcodeproj; sourceTree = "<group>"; };
|
||||||
14E0EEC81AB118F7000DECC3 /* RCTActionSheet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTActionSheet.xcodeproj; path = ../../Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj; sourceTree = "<group>"; };
|
14E0EEC81AB118F7000DECC3 /* RCTActionSheet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTActionSheet.xcodeproj; path = ../../Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj; sourceTree = "<group>"; };
|
||||||
D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = ../../Libraries/Vibration/RCTVibration.xcodeproj; sourceTree = "<group>"; };
|
D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = ../../Libraries/Vibration/RCTVibration.xcodeproj; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
@@ -135,6 +144,7 @@
|
|||||||
00D2771C1AB8C55500DC1E48 /* libicucore.dylib in Frameworks */,
|
00D2771C1AB8C55500DC1E48 /* libicucore.dylib in Frameworks */,
|
||||||
00D2771A1AB8C3E100DC1E48 /* libRCTWebSocketDebugger.a in Frameworks */,
|
00D2771A1AB8C3E100DC1E48 /* libRCTWebSocketDebugger.a in Frameworks */,
|
||||||
D85B829E1AB6D5D7003F4FE2 /* libRCTVibration.a in Frameworks */,
|
D85B829E1AB6D5D7003F4FE2 /* libRCTVibration.a in Frameworks */,
|
||||||
|
14DC67F41AB71881001358AB /* libRCTPushNotification.a in Frameworks */,
|
||||||
147CED4C1AB3532B00DA3E4C /* libRCTActionSheet.a in Frameworks */,
|
147CED4C1AB3532B00DA3E4C /* libRCTActionSheet.a in Frameworks */,
|
||||||
134454601AAFCABD003F0779 /* libRCTAdSupport.a in Frameworks */,
|
134454601AAFCABD003F0779 /* libRCTAdSupport.a in Frameworks */,
|
||||||
134A8A2A1AACED7A00945AAE /* libRCTGeolocation.a in Frameworks */,
|
134A8A2A1AACED7A00945AAE /* libRCTGeolocation.a in Frameworks */,
|
||||||
@@ -177,6 +187,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */,
|
D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */,
|
||||||
|
14DC67E71AB71876001358AB /* RCTPushNotification.xcodeproj */,
|
||||||
14E0EEC81AB118F7000DECC3 /* RCTActionSheet.xcodeproj */,
|
14E0EEC81AB118F7000DECC3 /* RCTActionSheet.xcodeproj */,
|
||||||
13417FFA1AA91531003F314A /* ReactKit.xcodeproj */,
|
13417FFA1AA91531003F314A /* ReactKit.xcodeproj */,
|
||||||
134454551AAFCAAE003F0779 /* RCTAdSupport.xcodeproj */,
|
134454551AAFCAAE003F0779 /* RCTAdSupport.xcodeproj */,
|
||||||
@@ -259,6 +270,14 @@
|
|||||||
name = Products;
|
name = Products;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
14DC67E81AB71876001358AB /* Products */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
14DC67F11AB71876001358AB /* libRCTPushNotification.a */,
|
||||||
|
);
|
||||||
|
name = Products;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
83CBB9F61A601CBA00E9B192 = {
|
83CBB9F61A601CBA00E9B192 = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@@ -371,6 +390,10 @@
|
|||||||
ProductGroup = 134180271AA91779003F314A /* Products */;
|
ProductGroup = 134180271AA91779003F314A /* Products */;
|
||||||
ProjectRef = 134180261AA91779003F314A /* RCTNetwork.xcodeproj */;
|
ProjectRef = 134180261AA91779003F314A /* RCTNetwork.xcodeproj */;
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ProductGroup = 14DC67E81AB71876001358AB /* Products */;
|
||||||
|
ProjectRef = 14DC67E71AB71876001358AB /* RCTPushNotification.xcodeproj */;
|
||||||
|
},
|
||||||
{
|
{
|
||||||
ProductGroup = 13417FEB1AA914B8003F314A /* Products */;
|
ProductGroup = 13417FEB1AA914B8003F314A /* Products */;
|
||||||
ProjectRef = 13417FEA1AA914B8003F314A /* RCTText.xcodeproj */;
|
ProjectRef = 13417FEA1AA914B8003F314A /* RCTText.xcodeproj */;
|
||||||
@@ -453,6 +476,13 @@
|
|||||||
remoteRef = 147CED4A1AB34F8C00DA3E4C /* PBXContainerItemProxy */;
|
remoteRef = 147CED4A1AB34F8C00DA3E4C /* PBXContainerItemProxy */;
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
};
|
};
|
||||||
|
14DC67F11AB71876001358AB /* libRCTPushNotification.a */ = {
|
||||||
|
isa = PBXReferenceProxy;
|
||||||
|
fileType = archive.ar;
|
||||||
|
path = libRCTPushNotification.a;
|
||||||
|
remoteRef = 14DC67F01AB71876001358AB /* PBXContainerItemProxy */;
|
||||||
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
|
};
|
||||||
D85B829C1AB6D5CE003F4FE2 /* libRCTVibration.a */ = {
|
D85B829C1AB6D5CE003F4FE2 /* libRCTVibration.a */ = {
|
||||||
isa = PBXReferenceProxy;
|
isa = PBXReferenceProxy;
|
||||||
fileType = archive.ar;
|
fileType = archive.ar;
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ var APIS = [
|
|||||||
require('./ActionSheetIOSExample'),
|
require('./ActionSheetIOSExample'),
|
||||||
require('./AdSupportIOSExample'),
|
require('./AdSupportIOSExample'),
|
||||||
require('./AlertIOSExample'),
|
require('./AlertIOSExample'),
|
||||||
require('./AppStateExample'),
|
|
||||||
require('./AppStateIOSExample'),
|
require('./AppStateIOSExample'),
|
||||||
require('./AsyncStorageExample'),
|
require('./AsyncStorageExample'),
|
||||||
require('./CameraRollExample.ios'),
|
require('./CameraRollExample.ios'),
|
||||||
@@ -56,6 +55,7 @@ var APIS = [
|
|||||||
require('./LayoutExample'),
|
require('./LayoutExample'),
|
||||||
require('./NetInfoExample'),
|
require('./NetInfoExample'),
|
||||||
require('./PointerEventsExample'),
|
require('./PointerEventsExample'),
|
||||||
|
require('./PushNotificationIOSExample'),
|
||||||
require('./StatusBarIOSExample'),
|
require('./StatusBarIOSExample'),
|
||||||
require('./TimerExample'),
|
require('./TimerExample'),
|
||||||
require('./VibrationIOSExample'),
|
require('./VibrationIOSExample'),
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the BSD-style license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
|
||||||
*
|
|
||||||
* @providesModule AppState
|
|
||||||
*/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var NativeModules = require('NativeModules');
|
|
||||||
var RCTAppState = NativeModules.AppState;
|
|
||||||
|
|
||||||
var AppState = {
|
|
||||||
|
|
||||||
setApplicationIconBadgeNumber: function(number) {
|
|
||||||
RCTAppState.setApplicationIconBadgeNumber(number);
|
|
||||||
},
|
|
||||||
|
|
||||||
getApplicationIconBadgeNumber: function(callback) {
|
|
||||||
RCTAppState.getApplicationIconBadgeNumber(callback);
|
|
||||||
},
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = AppState;
|
|
||||||
@@ -13,13 +13,12 @@
|
|||||||
|
|
||||||
var NativeModules = require('NativeModules');
|
var NativeModules = require('NativeModules');
|
||||||
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
||||||
|
var RCTPushNotificationManager = require('NativeModules').PushNotificationManager;
|
||||||
var RCTPushNotificationManager = NativeModules.PushNotificationManager;
|
var invariant = require('invariant');
|
||||||
if (RCTPushNotificationManager) {
|
|
||||||
var _initialNotification = RCTPushNotificationManager.initialNotification;
|
|
||||||
}
|
|
||||||
|
|
||||||
var _notifHandlers = {};
|
var _notifHandlers = {};
|
||||||
|
var _initialNotification = RCTPushNotificationManager &&
|
||||||
|
RCTPushNotificationManager.initialNotification;
|
||||||
|
|
||||||
var DEVICE_NOTIF_EVENT = 'remoteNotificationReceived';
|
var DEVICE_NOTIF_EVENT = 'remoteNotificationReceived';
|
||||||
|
|
||||||
@@ -29,6 +28,14 @@ class PushNotificationIOS {
|
|||||||
_sound: string;
|
_sound: string;
|
||||||
_badgeCount: number;
|
_badgeCount: number;
|
||||||
|
|
||||||
|
static setApplicationIconBadgeNumber(number) {
|
||||||
|
RCTPushNotificationManager.setApplicationIconBadgeNumber(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
static getApplicationIconBadgeNumber(callback) {
|
||||||
|
RCTPushNotificationManager.getApplicationIconBadgeNumber(callback);
|
||||||
|
}
|
||||||
|
|
||||||
static addEventListener(type, handler) {
|
static addEventListener(type, handler) {
|
||||||
_notifHandlers[handler] = RCTDeviceEventEmitter.addListener(
|
_notifHandlers[handler] = RCTDeviceEventEmitter.addListener(
|
||||||
DEVICE_NOTIF_EVENT,
|
DEVICE_NOTIF_EVENT,
|
||||||
@@ -38,6 +45,18 @@ class PushNotificationIOS {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static requestPermissions() {
|
||||||
|
RCTPushNotificationManager.requestPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
static checkPermissions(callback) {
|
||||||
|
invariant(
|
||||||
|
typeof callback === 'function',
|
||||||
|
'Must provide a valid callback'
|
||||||
|
);
|
||||||
|
RCTPushNotificationManager.checkPermissions(callback);
|
||||||
|
}
|
||||||
|
|
||||||
static removeEventListener(type, handler) {
|
static removeEventListener(type, handler) {
|
||||||
if (!_notifHandlers[handler]) {
|
if (!_notifHandlers[handler]) {
|
||||||
return;
|
return;
|
||||||
@@ -0,0 +1,256 @@
|
|||||||
|
// !$*UTF8*$!
|
||||||
|
{
|
||||||
|
archiveVersion = 1;
|
||||||
|
classes = {
|
||||||
|
};
|
||||||
|
objectVersion = 46;
|
||||||
|
objects = {
|
||||||
|
|
||||||
|
/* Begin PBXBuildFile section */
|
||||||
|
148699CF1ABD045300480536 /* RCTPushNotificationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 148699CE1ABD045300480536 /* RCTPushNotificationManager.m */; };
|
||||||
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
|
/* Begin PBXCopyFilesBuildPhase section */
|
||||||
|
58B511D91A9E6C8500147676 /* CopyFiles */ = {
|
||||||
|
isa = PBXCopyFilesBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
dstPath = "include/$(PRODUCT_NAME)";
|
||||||
|
dstSubfolderSpec = 16;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXCopyFilesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXFileReference section */
|
||||||
|
134814201AA4EA6300B7C361 /* libRCTPushNotification.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTPushNotification.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
|
148699CD1ABD045300480536 /* RCTPushNotificationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTPushNotificationManager.h; sourceTree = "<group>"; };
|
||||||
|
148699CE1ABD045300480536 /* RCTPushNotificationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTPushNotificationManager.m; sourceTree = "<group>"; };
|
||||||
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
58B511D81A9E6C8500147676 /* Frameworks */ = {
|
||||||
|
isa = PBXFrameworksBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXFrameworksBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXGroup section */
|
||||||
|
134814211AA4EA7D00B7C361 /* Products */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
134814201AA4EA6300B7C361 /* libRCTPushNotification.a */,
|
||||||
|
);
|
||||||
|
name = Products;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
58B511D21A9E6C8500147676 = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
148699CD1ABD045300480536 /* RCTPushNotificationManager.h */,
|
||||||
|
148699CE1ABD045300480536 /* RCTPushNotificationManager.m */,
|
||||||
|
134814211AA4EA7D00B7C361 /* Products */,
|
||||||
|
);
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
/* End PBXGroup section */
|
||||||
|
|
||||||
|
/* Begin PBXNativeTarget section */
|
||||||
|
58B511DA1A9E6C8500147676 /* RCTPushNotification */ = {
|
||||||
|
isa = PBXNativeTarget;
|
||||||
|
buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RCTPushNotification" */;
|
||||||
|
buildPhases = (
|
||||||
|
58B511D71A9E6C8500147676 /* Sources */,
|
||||||
|
58B511D81A9E6C8500147676 /* Frameworks */,
|
||||||
|
58B511D91A9E6C8500147676 /* CopyFiles */,
|
||||||
|
);
|
||||||
|
buildRules = (
|
||||||
|
);
|
||||||
|
dependencies = (
|
||||||
|
);
|
||||||
|
name = RCTPushNotification;
|
||||||
|
productName = RCTDataManager;
|
||||||
|
productReference = 134814201AA4EA6300B7C361 /* libRCTPushNotification.a */;
|
||||||
|
productType = "com.apple.product-type.library.static";
|
||||||
|
};
|
||||||
|
/* End PBXNativeTarget section */
|
||||||
|
|
||||||
|
/* Begin PBXProject section */
|
||||||
|
58B511D31A9E6C8500147676 /* Project object */ = {
|
||||||
|
isa = PBXProject;
|
||||||
|
attributes = {
|
||||||
|
LastUpgradeCheck = 0610;
|
||||||
|
ORGANIZATIONNAME = Facebook;
|
||||||
|
TargetAttributes = {
|
||||||
|
58B511DA1A9E6C8500147676 = {
|
||||||
|
CreatedOnToolsVersion = 6.1.1;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RCTPushNotification" */;
|
||||||
|
compatibilityVersion = "Xcode 3.2";
|
||||||
|
developmentRegion = English;
|
||||||
|
hasScannedForEncodings = 0;
|
||||||
|
knownRegions = (
|
||||||
|
en,
|
||||||
|
);
|
||||||
|
mainGroup = 58B511D21A9E6C8500147676;
|
||||||
|
productRefGroup = 58B511D21A9E6C8500147676;
|
||||||
|
projectDirPath = "";
|
||||||
|
projectRoot = "";
|
||||||
|
targets = (
|
||||||
|
58B511DA1A9E6C8500147676 /* RCTPushNotification */,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
/* End PBXProject section */
|
||||||
|
|
||||||
|
/* Begin PBXSourcesBuildPhase section */
|
||||||
|
58B511D71A9E6C8500147676 /* Sources */ = {
|
||||||
|
isa = PBXSourcesBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
148699CF1ABD045300480536 /* RCTPushNotificationManager.m in Sources */,
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXSourcesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin XCBuildConfiguration section */
|
||||||
|
58B511ED1A9E6C8500147676 /* Debug */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||||
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
|
CLANG_ENABLE_MODULES = YES;
|
||||||
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
|
CLANG_WARN_EMPTY_BODY = YES;
|
||||||
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
|
COPY_PHASE_STRIP = NO;
|
||||||
|
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||||
|
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||||
|
GCC_DYNAMIC_NO_PIC = NO;
|
||||||
|
GCC_OPTIMIZATION_LEVEL = 0;
|
||||||
|
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||||
|
"DEBUG=1",
|
||||||
|
"$(inherited)",
|
||||||
|
);
|
||||||
|
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||||
|
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||||
|
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||||
|
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||||
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
|
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
|
||||||
|
MTL_ENABLE_DEBUG_INFO = YES;
|
||||||
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
|
SDKROOT = iphoneos;
|
||||||
|
};
|
||||||
|
name = Debug;
|
||||||
|
};
|
||||||
|
58B511EE1A9E6C8500147676 /* Release */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||||
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
|
CLANG_ENABLE_MODULES = YES;
|
||||||
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
|
CLANG_WARN_EMPTY_BODY = YES;
|
||||||
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
|
COPY_PHASE_STRIP = YES;
|
||||||
|
ENABLE_NS_ASSERTIONS = NO;
|
||||||
|
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||||
|
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||||
|
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||||
|
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||||
|
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||||
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
|
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
|
||||||
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
|
SDKROOT = iphoneos;
|
||||||
|
VALIDATE_PRODUCT = YES;
|
||||||
|
};
|
||||||
|
name = Release;
|
||||||
|
};
|
||||||
|
58B511F01A9E6C8500147676 /* Debug */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
HEADER_SEARCH_PATHS = (
|
||||||
|
"$(inherited)",
|
||||||
|
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
||||||
|
"$(SRCROOT)/../../ReactKit/**",
|
||||||
|
);
|
||||||
|
LIBRARY_SEARCH_PATHS = (
|
||||||
|
"$(inherited)",
|
||||||
|
"/Users/nicklockwood/fbobjc-hg/Libraries/FBReactKit/js/react-native-github/ReactKit/build/Debug-iphoneos",
|
||||||
|
);
|
||||||
|
OTHER_LDFLAGS = "-ObjC";
|
||||||
|
PRODUCT_NAME = RCTPushNotification;
|
||||||
|
SKIP_INSTALL = YES;
|
||||||
|
};
|
||||||
|
name = Debug;
|
||||||
|
};
|
||||||
|
58B511F11A9E6C8500147676 /* Release */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
HEADER_SEARCH_PATHS = (
|
||||||
|
"$(inherited)",
|
||||||
|
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
|
||||||
|
"$(SRCROOT)/../../ReactKit/**",
|
||||||
|
);
|
||||||
|
LIBRARY_SEARCH_PATHS = (
|
||||||
|
"$(inherited)",
|
||||||
|
"/Users/nicklockwood/fbobjc-hg/Libraries/FBReactKit/js/react-native-github/ReactKit/build/Debug-iphoneos",
|
||||||
|
);
|
||||||
|
OTHER_LDFLAGS = "-ObjC";
|
||||||
|
PRODUCT_NAME = RCTPushNotification;
|
||||||
|
SKIP_INSTALL = YES;
|
||||||
|
};
|
||||||
|
name = Release;
|
||||||
|
};
|
||||||
|
/* End XCBuildConfiguration section */
|
||||||
|
|
||||||
|
/* Begin XCConfigurationList section */
|
||||||
|
58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RCTPushNotification" */ = {
|
||||||
|
isa = XCConfigurationList;
|
||||||
|
buildConfigurations = (
|
||||||
|
58B511ED1A9E6C8500147676 /* Debug */,
|
||||||
|
58B511EE1A9E6C8500147676 /* Release */,
|
||||||
|
);
|
||||||
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
|
};
|
||||||
|
58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RCTPushNotification" */ = {
|
||||||
|
isa = XCConfigurationList;
|
||||||
|
buildConfigurations = (
|
||||||
|
58B511F01A9E6C8500147676 /* Debug */,
|
||||||
|
58B511F11A9E6C8500147676 /* Release */,
|
||||||
|
);
|
||||||
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
|
};
|
||||||
|
/* End XCConfigurationList section */
|
||||||
|
};
|
||||||
|
rootObject = 58B511D31A9E6C8500147676 /* Project object */;
|
||||||
|
}
|
||||||
@@ -7,13 +7,16 @@
|
|||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import <FBReactKit/RCTBridgeModule.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
extern NSString *const RKRemoteNotificationReceived;
|
#import "../../ReactKit/Base/RCTBridgeModule.h"
|
||||||
extern NSString *const RKOpenURLNotification;
|
|
||||||
|
|
||||||
@interface RCTPushNotificationManager : NSObject <RCTBridgeModule>
|
@interface RCTPushNotificationManager : NSObject <RCTBridgeModule>
|
||||||
|
|
||||||
- (instancetype)initWithInitialNotification:(NSDictionary *)initialNotification NS_DESIGNATED_INITIALIZER;
|
- (instancetype)initWithInitialNotification:(NSDictionary *)initialNotification NS_DESIGNATED_INITIALIZER;
|
||||||
|
|
||||||
|
+ (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
|
||||||
|
+ (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification;
|
||||||
|
+ (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
156
Libraries/PushNotificationIOS/RCTPushNotificationManager.m
Normal file
156
Libraries/PushNotificationIOS/RCTPushNotificationManager.m
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "RCTPushNotificationManager.h"
|
||||||
|
|
||||||
|
#import "RCTBridge.h"
|
||||||
|
#import "RCTEventDispatcher.h"
|
||||||
|
|
||||||
|
NSString *const RCTRemoteNotificationReceived = @"RemoteNotificationReceived";
|
||||||
|
NSString *const RCTOpenURLNotification = @"RCTOpenURLNotification";
|
||||||
|
|
||||||
|
@implementation RCTPushNotificationManager
|
||||||
|
{
|
||||||
|
NSDictionary *_initialNotification;
|
||||||
|
}
|
||||||
|
|
||||||
|
@synthesize bridge = _bridge;
|
||||||
|
|
||||||
|
- (instancetype)init
|
||||||
|
{
|
||||||
|
return [self initWithInitialNotification:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithInitialNotification:(NSDictionary *)initialNotification
|
||||||
|
{
|
||||||
|
if ((self = [super init])) {
|
||||||
|
_initialNotification = [initialNotification copy];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(handleRemoteNotificationReceived:)
|
||||||
|
name:RCTRemoteNotificationReceived
|
||||||
|
object:nil];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(handleOpenURLNotification:)
|
||||||
|
name:RCTOpenURLNotification
|
||||||
|
object:nil];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
|
||||||
|
{
|
||||||
|
#ifdef __IPHONE_8_0
|
||||||
|
[application registerForRemoteNotifications];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
|
||||||
|
{
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationReceived
|
||||||
|
object:self
|
||||||
|
userInfo:notification];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (BOOL)application:(UIApplication *)application
|
||||||
|
openURL:(NSURL *)url
|
||||||
|
sourceApplication:(NSString *)sourceApplication
|
||||||
|
annotation:(id)annotation
|
||||||
|
{
|
||||||
|
NSDictionary *payload = @{@"url": [url absoluteString]};
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTOpenURLNotification
|
||||||
|
object:self
|
||||||
|
userInfo:payload];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)handleRemoteNotificationReceived:(NSNotification *)notification
|
||||||
|
{
|
||||||
|
[_bridge.eventDispatcher sendDeviceEventWithName:@"remoteNotificationReceived"
|
||||||
|
body:[notification userInfo]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)handleOpenURLNotification:(NSNotification *)notification
|
||||||
|
{
|
||||||
|
[_bridge.eventDispatcher sendDeviceEventWithName:@"openURL"
|
||||||
|
body:[notification userInfo]];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the application icon badge number on the home screen
|
||||||
|
*/
|
||||||
|
+ (void)setApplicationIconBadgeNumber:(NSInteger)number
|
||||||
|
{
|
||||||
|
RCT_EXPORT();
|
||||||
|
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
[self requestPermissions];
|
||||||
|
});
|
||||||
|
|
||||||
|
[UIApplication sharedApplication].applicationIconBadgeNumber = number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current application icon badge number on the home screen
|
||||||
|
*/
|
||||||
|
+ (void)getApplicationIconBadgeNumber:(RCTResponseSenderBlock)callback
|
||||||
|
{
|
||||||
|
RCT_EXPORT();
|
||||||
|
|
||||||
|
callback(@[
|
||||||
|
@([UIApplication sharedApplication].applicationIconBadgeNumber)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void)requestPermissions
|
||||||
|
{
|
||||||
|
RCT_EXPORT();
|
||||||
|
|
||||||
|
#ifdef __IPHONE_8_0
|
||||||
|
UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;
|
||||||
|
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
|
||||||
|
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
|
||||||
|
#else
|
||||||
|
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void)checkPermissions:(RCTResponseSenderBlock)callback
|
||||||
|
{
|
||||||
|
RCT_EXPORT();
|
||||||
|
|
||||||
|
NSMutableDictionary *permissions = [[NSMutableDictionary alloc] init];
|
||||||
|
#ifdef __IPHONE_8_0
|
||||||
|
UIUserNotificationType types = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
|
||||||
|
permissions[@"alert"] = @((BOOL)(types & UIUserNotificationTypeAlert));
|
||||||
|
permissions[@"badge"] = @((BOOL)(types & UIUserNotificationTypeBadge));
|
||||||
|
permissions[@"sound"] = @((BOOL)(types & UIUserNotificationTypeSound));
|
||||||
|
#else
|
||||||
|
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
|
||||||
|
permissions[@"alert"] = @((BOOL)(types & UIRemoteNotificationTypeAlert));
|
||||||
|
permissions[@"badge"] = @((BOOL)(types & UIRemoteNotificationTypeBadge));
|
||||||
|
permissions[@"sound"] = @((BOOL)(types & UIRemoteNotificationTypeSound));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
callback(@[permissions]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSDictionary *)constantsToExport
|
||||||
|
{
|
||||||
|
return @{
|
||||||
|
@"initialNotification": _initialNotification ?: [NSNull null]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
2
Libraries/react-native/react-native.js
vendored
2
Libraries/react-native/react-native.js
vendored
@@ -42,7 +42,6 @@ var ReactNative = Object.assign(Object.create(require('React')), {
|
|||||||
AlertIOS: require('AlertIOS'),
|
AlertIOS: require('AlertIOS'),
|
||||||
Animation: require('Animation'),
|
Animation: require('Animation'),
|
||||||
AppRegistry: require('AppRegistry'),
|
AppRegistry: require('AppRegistry'),
|
||||||
AppState: require('AppState'),
|
|
||||||
AppStateIOS: require('AppStateIOS'),
|
AppStateIOS: require('AppStateIOS'),
|
||||||
AsyncStorage: require('AsyncStorage'),
|
AsyncStorage: require('AsyncStorage'),
|
||||||
CameraRoll: require('CameraRoll'),
|
CameraRoll: require('CameraRoll'),
|
||||||
@@ -50,6 +49,7 @@ var ReactNative = Object.assign(Object.create(require('React')), {
|
|||||||
LayoutAnimation: require('LayoutAnimation'),
|
LayoutAnimation: require('LayoutAnimation'),
|
||||||
NetInfo: require('NetInfo'),
|
NetInfo: require('NetInfo'),
|
||||||
PixelRatio: require('PixelRatio'),
|
PixelRatio: require('PixelRatio'),
|
||||||
|
PushNotificationIOS: require('PushNotificationIOS'),
|
||||||
StatusBarIOS: require('StatusBarIOS'),
|
StatusBarIOS: require('StatusBarIOS'),
|
||||||
StyleSheet: require('StyleSheet'),
|
StyleSheet: require('StyleSheet'),
|
||||||
TimerMixin: require('TimerMixin'),
|
TimerMixin: require('TimerMixin'),
|
||||||
|
|||||||
@@ -87,26 +87,4 @@ static NSString *RCTCurrentAppBackgroundState()
|
|||||||
callback(@[@{@"app_state": _lastKnownState}]);
|
callback(@[@{@"app_state": _lastKnownState}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the application icon badge number on the home screen
|
|
||||||
*/
|
|
||||||
- (void)setApplicationIconBadgeNumber:(NSInteger)number
|
|
||||||
{
|
|
||||||
RCT_EXPORT();
|
|
||||||
|
|
||||||
[UIApplication sharedApplication].applicationIconBadgeNumber = number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current application icon badge number on the home screen
|
|
||||||
*/
|
|
||||||
- (void)getApplicationIconBadgeNumber:(RCTResponseSenderBlock)callback
|
|
||||||
{
|
|
||||||
RCT_EXPORT();
|
|
||||||
|
|
||||||
callback(@[
|
|
||||||
@([UIApplication sharedApplication].applicationIconBadgeNumber)
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the BSD-style license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#import "RCTPushNotificationManager.h"
|
|
||||||
|
|
||||||
#import "RCTAssert.h"
|
|
||||||
#import "RCTBridge.h"
|
|
||||||
#import "RCTEventDispatcher.h"
|
|
||||||
|
|
||||||
NSString *const RKRemoteNotificationReceived = @"RemoteNotificationReceived";
|
|
||||||
NSString *const RKOpenURLNotification = @"RKOpenURLNotification";
|
|
||||||
|
|
||||||
@implementation RCTPushNotificationManager
|
|
||||||
{
|
|
||||||
NSDictionary *_initialNotification;
|
|
||||||
}
|
|
||||||
|
|
||||||
@synthesize bridge = _bridge;
|
|
||||||
|
|
||||||
- (instancetype)init
|
|
||||||
{
|
|
||||||
return [self initWithInitialNotification:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)initWithInitialNotification:(NSDictionary *)initialNotification
|
|
||||||
{
|
|
||||||
if ((self = [super init])) {
|
|
||||||
_initialNotification = [initialNotification copy];
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
||||||
selector:@selector(handleRemoteNotificationReceived:)
|
|
||||||
name:RKRemoteNotificationReceived
|
|
||||||
object:nil];
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
||||||
selector:@selector(handleOpenURLNotification:)
|
|
||||||
name:RKOpenURLNotification
|
|
||||||
object:nil];
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)handleRemoteNotificationReceived:(NSNotification *)notification
|
|
||||||
{
|
|
||||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"remoteNotificationReceived"
|
|
||||||
body:[notification userInfo]];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)handleOpenURLNotification:(NSNotification *)notification
|
|
||||||
{
|
|
||||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"openURL"
|
|
||||||
body:[notification userInfo]];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSDictionary *)constantsToExport
|
|
||||||
{
|
|
||||||
return @{
|
|
||||||
@"initialNotification": _initialNotification ?: [NSNull null]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)dealloc
|
|
||||||
{
|
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
Reference in New Issue
Block a user