Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-notifications
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
冷佳娟
react-native-notifications
Commits
4452be90
Commit
4452be90
authored
Jan 16, 2017
by
Raymond Penners
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose registration failure event
parent
a269d823
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
0 deletions
+43
-0
README.md
README.md
+17
-0
RNNotifications/RNNotifications.h
RNNotifications/RNNotifications.h
+1
-0
RNNotifications/RNNotifications.m
RNNotifications/RNNotifications.m
+17
-0
index.ios.js
index.ios.js
+7
-0
test/index.ios.spec.js
test/index.ios.spec.js
+1
-0
No files found.
README.md
View file @
4452be90
...
@@ -58,6 +58,10 @@ And the following methods to support registration and receiving notifications:
...
@@ -58,6 +58,10 @@ And the following methods to support registration and receiving notifications:
[RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
[RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[RNNotifications didFailToRegisterForRemoteNotificationsWithError:error];
}
// Required for the notification event.
// Required for the notification event.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification {
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification {
[RNNotifications didReceiveRemoteNotification:notification];
[RNNotifications didReceiveRemoteNotification:notification];
...
@@ -151,6 +155,7 @@ import NotificationsIOS from 'react-native-notifications';
...
@@ -151,6 +155,7 @@ import NotificationsIOS from 'react-native-notifications';
class App extends Component {
class App extends Component {
constructor() {
constructor() {
NotificationsIOS.addEventListener('remoteNotificationsRegistered', this.onPushRegistered.bind(this));
NotificationsIOS.addEventListener('remoteNotificationsRegistered', this.onPushRegistered.bind(this));
NotificationsIOS.addEventListener('remoteNotificationsRegistrationFailed', this.onPushRegistrationFaled.bind(this));
NotificationsIOS.requestPermissions();
NotificationsIOS.requestPermissions();
}
}
...
@@ -158,9 +163,21 @@ class App extends Component {
...
@@ -158,9 +163,21 @@ class App extends Component {
console.log("Device Token Received", deviceToken);
console.log("Device Token Received", deviceToken);
}
}
onPushRegistrationFailed(error) {
// For example
:
//
// error={
// domain
:
'
NSCocoaErroDomain'
,
// code
:
3010,
// localizedDescription
:
'
remote
notifications
are
not
supported
in
the
simulator'
// }
console.error(error);
}
componentWillUnmount() {
componentWillUnmount() {
// prevent memory leaks!
// prevent memory leaks!
NotificationsIOS.removeEventListener('remoteNotificationsRegistered', this.onPushRegistered.bind(this));
NotificationsIOS.removeEventListener('remoteNotificationsRegistered', this.onPushRegistered.bind(this));
NotificationsIOS.removeEventListener('remoteNotificationsRegistrationFailed', this.onPushRegistrationFailed.bind(this));
}
}
}
}
...
...
RNNotifications/RNNotifications.h
View file @
4452be90
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
@interface
RNNotifications
:
NSObject
<
RCTBridgeModule
>
@interface
RNNotifications
:
NSObject
<
RCTBridgeModule
>
+
(
void
)
didRegisterForRemoteNotificationsWithDeviceToken
:(
NSData
*
)
deviceToken
;
+
(
void
)
didRegisterForRemoteNotificationsWithDeviceToken
:(
NSData
*
)
deviceToken
;
+
(
void
)
didFailToRegisterForRemoteNotificationsWithError
:(
NSError
*
)
error
;
+
(
void
)
didRegisterUserNotificationSettings
:(
UIUserNotificationSettings
*
)
notificationSettings
;
+
(
void
)
didRegisterUserNotificationSettings
:(
UIUserNotificationSettings
*
)
notificationSettings
;
+
(
void
)
didUpdatePushCredentials
:(
PKPushCredentials
*
)
credentials
forType
:(
NSString
*
)
type
;
+
(
void
)
didUpdatePushCredentials
:(
PKPushCredentials
*
)
credentials
forType
:(
NSString
*
)
type
;
...
...
RNNotifications/RNNotifications.m
View file @
4452be90
...
@@ -12,6 +12,7 @@ NSString* const RNNotificationCreateAction = @"CREATE";
...
@@ -12,6 +12,7 @@ NSString* const RNNotificationCreateAction = @"CREATE";
NSString
*
const
RNNotificationClearAction
=
@"CLEAR"
;
NSString
*
const
RNNotificationClearAction
=
@"CLEAR"
;
NSString
*
const
RNNotificationsRegistered
=
@"RNNotificationsRegistered"
;
NSString
*
const
RNNotificationsRegistered
=
@"RNNotificationsRegistered"
;
NSString
*
const
RNNotificationsRegistrationFailed
=
@"RNNotificationsRegistrationFailed"
;
NSString
*
const
RNPushKitRegistered
=
@"RNPushKitRegistered"
;
NSString
*
const
RNPushKitRegistered
=
@"RNPushKitRegistered"
;
NSString
*
const
RNNotificationReceivedForeground
=
@"RNNotificationReceivedForeground"
;
NSString
*
const
RNNotificationReceivedForeground
=
@"RNNotificationReceivedForeground"
;
NSString
*
const
RNNotificationReceivedBackground
=
@"RNNotificationReceivedBackground"
;
NSString
*
const
RNNotificationReceivedBackground
=
@"RNNotificationReceivedBackground"
;
...
@@ -118,6 +119,11 @@ RCT_EXPORT_MODULE()
...
@@ -118,6 +119,11 @@ RCT_EXPORT_MODULE()
name:
RNNotificationsRegistered
name:
RNNotificationsRegistered
object:
nil
];
object:
nil
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector:
@selector
(
handleNotificationsRegistrationFailed
:)
name:
RNNotificationsRegistrationFailed
object:
nil
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector:
@selector
(
handlePushKitRegistered
:)
selector:
@selector
(
handlePushKitRegistered
:)
name:
RNPushKitRegistered
name:
RNPushKitRegistered
...
@@ -164,6 +170,12 @@ RCT_EXPORT_MODULE()
...
@@ -164,6 +170,12 @@ RCT_EXPORT_MODULE()
userInfo:
@{
@"deviceToken"
:
[
self
deviceTokenToString
:
deviceToken
]}];
userInfo:
@{
@"deviceToken"
:
[
self
deviceTokenToString
:
deviceToken
]}];
}
}
+
(
void
)
didFailToRegisterForRemoteNotificationsWithError
:(
NSError
*
)
error
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
RNNotificationsRegistrationFailed
object:
self
userInfo:
@{
@"code"
:
[
NSNumber
numberWithInteger
:
error
.
code
],
@"domain"
:
error
.
domain
,
@"localizedDescription"
:
error
.
localizedDescription
}];
}
+
(
void
)
didReceiveRemoteNotification
:(
NSDictionary
*
)
notification
+
(
void
)
didReceiveRemoteNotification
:(
NSDictionary
*
)
notification
{
{
UIApplicationState
state
=
[
UIApplication
sharedApplication
].
applicationState
;
UIApplicationState
state
=
[
UIApplication
sharedApplication
].
applicationState
;
...
@@ -389,6 +401,11 @@ RCT_EXPORT_MODULE()
...
@@ -389,6 +401,11 @@ RCT_EXPORT_MODULE()
[
_bridge
.
eventDispatcher
sendDeviceEventWithName
:
@"remoteNotificationsRegistered"
body
:
notification
.
userInfo
];
[
_bridge
.
eventDispatcher
sendDeviceEventWithName
:
@"remoteNotificationsRegistered"
body
:
notification
.
userInfo
];
}
}
-
(
void
)
handleNotificationsRegistrationFailed
:(
NSNotification
*
)
notification
{
[
_bridge
.
eventDispatcher
sendDeviceEventWithName
:
@"remoteNotificationsRegistrationFailed"
body
:
notification
.
userInfo
];
}
-
(
void
)
handlePushKitRegistered
:(
NSNotification
*
)
notification
-
(
void
)
handlePushKitRegistered
:(
NSNotification
*
)
notification
{
{
[
_bridge
.
eventDispatcher
sendDeviceEventWithName
:
@"pushKitRegistered"
body
:
notification
.
userInfo
];
[
_bridge
.
eventDispatcher
sendDeviceEventWithName
:
@"pushKitRegistered"
body
:
notification
.
userInfo
];
...
...
index.ios.js
View file @
4452be90
...
@@ -10,6 +10,7 @@ const NativeRNNotifications = NativeModules.RNNotifications; // eslint-disable-l
...
@@ -10,6 +10,7 @@ const NativeRNNotifications = NativeModules.RNNotifications; // eslint-disable-l
import
IOSNotification
from
"
./notification.ios
"
;
import
IOSNotification
from
"
./notification.ios
"
;
export
const
DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT
=
"
remoteNotificationsRegistered
"
;
export
const
DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT
=
"
remoteNotificationsRegistered
"
;
export
const
DEVICE_REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT
=
"
remoteNotificationsRegistrationFailed
"
;
export
const
DEVICE_PUSH_KIT_REGISTERED_EVENT
=
"
pushKitRegistered
"
;
export
const
DEVICE_PUSH_KIT_REGISTERED_EVENT
=
"
pushKitRegistered
"
;
export
const
DEVICE_NOTIFICATION_RECEIVED_FOREGROUND_EVENT
=
"
notificationReceivedForeground
"
;
export
const
DEVICE_NOTIFICATION_RECEIVED_FOREGROUND_EVENT
=
"
notificationReceivedForeground
"
;
export
const
DEVICE_NOTIFICATION_RECEIVED_BACKGROUND_EVENT
=
"
notificationReceivedBackground
"
;
export
const
DEVICE_NOTIFICATION_RECEIVED_BACKGROUND_EVENT
=
"
notificationReceivedBackground
"
;
...
@@ -19,6 +20,7 @@ const DEVICE_NOTIFICATION_ACTION_RECEIVED = "notificationActionReceived";
...
@@ -19,6 +20,7 @@ const DEVICE_NOTIFICATION_ACTION_RECEIVED = "notificationActionReceived";
const
_exportedEvents
=
[
const
_exportedEvents
=
[
DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT
,
DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT
,
DEVICE_REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT
,
DEVICE_PUSH_KIT_REGISTERED_EVENT
,
DEVICE_PUSH_KIT_REGISTERED_EVENT
,
DEVICE_NOTIFICATION_RECEIVED_FOREGROUND_EVENT
,
DEVICE_NOTIFICATION_RECEIVED_FOREGROUND_EVENT
,
DEVICE_NOTIFICATION_RECEIVED_BACKGROUND_EVENT
,
DEVICE_NOTIFICATION_RECEIVED_BACKGROUND_EVENT
,
...
@@ -62,6 +64,11 @@ export default class NotificationsIOS {
...
@@ -62,6 +64,11 @@ export default class NotificationsIOS {
DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT
,
DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT
,
registration
=>
handler
(
registration
.
deviceToken
)
registration
=>
handler
(
registration
.
deviceToken
)
);
);
}
else
if
(
type
===
DEVICE_REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT
)
{
listener
=
DeviceEventEmitter
.
addListener
(
DEVICE_REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT
,
error
=>
handler
(
error
)
);
}
else
if
(
type
===
DEVICE_PUSH_KIT_REGISTERED_EVENT
)
{
}
else
if
(
type
===
DEVICE_PUSH_KIT_REGISTERED_EVENT
)
{
listener
=
DeviceEventEmitter
.
addListener
(
listener
=
DeviceEventEmitter
.
addListener
(
DEVICE_PUSH_KIT_REGISTERED_EVENT
,
DEVICE_PUSH_KIT_REGISTERED_EVENT
,
...
...
test/index.ios.spec.js
View file @
4452be90
...
@@ -9,6 +9,7 @@ describe("NotificationsIOS", () => {
...
@@ -9,6 +9,7 @@ describe("NotificationsIOS", () => {
let
deviceEvents
=
[
let
deviceEvents
=
[
"
pushKitRegistered
"
,
"
pushKitRegistered
"
,
"
remoteNotificationsRegistered
"
,
"
remoteNotificationsRegistered
"
,
"
remoteNotificationsRegistrationFailed
"
,
"
notificationReceivedForeground
"
,
"
notificationReceivedForeground
"
,
"
notificationReceivedBackground
"
,
"
notificationReceivedBackground
"
,
"
notificationOpened
"
"
notificationOpened
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment