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
df53f390
Commit
df53f390
authored
Jul 08, 2019
by
yogevbd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
961f9a8b
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
76 additions
and
61 deletions
+76
-61
RNNotifications/RNBridgeModule.m
RNNotifications/RNBridgeModule.m
+2
-5
RNNotifications/RNCommandsHandler.h
RNNotifications/RNCommandsHandler.h
+0
-2
RNNotifications/RNCommandsHandler.m
RNNotifications/RNCommandsHandler.m
+2
-9
RNNotifications/RNEventEmitter.h
RNNotifications/RNEventEmitter.h
+4
-6
RNNotifications/RNEventEmitter.m
RNNotifications/RNEventEmitter.m
+26
-16
RNNotifications/RNNotificationEventHandler.h
RNNotifications/RNNotificationEventHandler.h
+1
-0
RNNotifications/RNNotifications.h
RNNotifications/RNNotifications.h
+3
-0
RNNotifications/RNNotifications.m
RNNotifications/RNNotifications.m
+17
-1
RNNotifications/RNNotifications.xcodeproj/project.pbxproj
RNNotifications/RNNotifications.xcodeproj/project.pbxproj
+0
-12
RNNotifications/RNPushKitEventListener.m
RNNotifications/RNPushKitEventListener.m
+0
-1
example/index.ios.js
example/index.ios.js
+5
-0
example/ios/NotificationsExampleApp/AppDelegate.h
example/ios/NotificationsExampleApp/AppDelegate.h
+1
-3
example/ios/NotificationsExampleApp/AppDelegate.m
example/ios/NotificationsExampleApp/AppDelegate.m
+7
-6
example/ios/NotificationsExampleApp/NotificationsExampleApp.entitlements
...ificationsExampleApp/NotificationsExampleApp.entitlements
+8
-0
No files found.
RNNotifications/RNBridgeModule.m
View file @
df53f390
#import "RNBridgeModule.h"
#import "RNCommandsHandler.h"
#import "RCTConvert+Notifications.h"
#import "RNEventEmitter.h"
#import "RNNotifications.h"
#import
"RNNotificationsStore.h"
#import
<React/RCTBridgeDelegate.h>
@implementation
RNBridgeModule
{
RNNotificationsStore
*
_store
;
RNCommandsHandler
*
_commandsHandler
;
}
...
...
@@ -16,7 +14,6 @@ RCT_EXPORT_MODULE();
-
(
instancetype
)
init
{
self
=
[
super
init
];
_store
=
[
RNNotificationsStore
new
];
_commandsHandler
=
[[
RNCommandsHandler
alloc
]
init
];
return
self
;
}
...
...
@@ -31,7 +28,7 @@ RCT_EXPORT_MODULE();
-
(
void
)
setBridge
:(
RCTBridge
*
)
bridge
{
_bridge
=
bridge
;
_store
.
initialNotification
=
[
_bridge
.
launchOptions
objectForKey
:
UIApplicationLaunchOptionsRemoteNotificationKey
];
[[
RNNotifications
sharedInstance
]
setInitialNotification
:[
_bridge
.
launchOptions
objectForKey
:
UIApplicationLaunchOptionsRemoteNotificationKey
]
];
}
#pragma mark - JS interface
...
...
RNNotifications/RNCommandsHandler.h
View file @
df53f390
...
...
@@ -4,8 +4,6 @@
@interface
RNCommandsHandler
:
NSObject
-
(
instancetype
)
initWithStore
:(
RNNotificationsStore
*
)
store
;
-
(
void
)
requestPermissionsWithCategories
:(
NSArray
*
)
json
;
-
(
void
)
getInitialNotification
:(
RCTPromiseResolveBlock
)
resolve
reject
:(
RCTPromiseRejectBlock
)
reject
;
...
...
RNNotifications/RNCommandsHandler.m
View file @
df53f390
...
...
@@ -5,13 +5,6 @@
@implementation
RNCommandsHandler
{
RNPushKit
*
_pushKit
;
RNNotificationsStore
*
_store
;
}
-
(
instancetype
)
initWithStore
:(
RNNotificationsStore
*
)
store
{
self
=
[
super
init
];
_store
=
store
;
return
self
;
}
-
(
void
)
requestPermissionsWithCategories
:(
NSArray
*
)
json
{
...
...
@@ -45,11 +38,11 @@
}
-
(
void
)
getInitialNotification
:(
RCTPromiseResolveBlock
)
resolve
reject
:(
RCTPromiseRejectBlock
)
reject
{
resolve
(
_store
.
initialNotification
);
resolve
(
[[
RNNotifications
sharedInstance
]
initialNotification
]
);
}
-
(
void
)
completionHandler
:(
NSString
*
)
completionKey
{
[
_store
completeAction
:
completionKey
];
[
[
RNNotifications
sharedInstance
]
finishHandleNotificationKey
:
completionKey
];
}
-
(
void
)
abandonPermissions
{
...
...
RNNotifications/RNEventEmitter.h
View file @
df53f390
#import
"RCTEventEmitter.h"
#import
<React/RCTEventEmitter.h>
static
NSString
*
const
RNRegistered
=
@"
n
otificationsRegistered"
;
static
NSString
*
const
RNRegistrationFailed
=
@"
n
otificationsRegistrationFailed"
;
static
NSString
*
const
RNRegistered
=
@"
remoteN
otificationsRegistered"
;
static
NSString
*
const
RNRegistrationFailed
=
@"
remoteN
otificationsRegistrationFailed"
;
static
NSString
*
const
RNPushKitRegistered
=
@"pushKitRegistered"
;
static
NSString
*
const
RNNotificationReceivedForeground
=
@"notificationReceivedForeground"
;
static
NSString
*
const
RNNotificationReceivedBackground
=
@"notificationReceivedBackground"
;
...
...
@@ -9,9 +9,7 @@ static NSString* const RNNotificationOpened = @"notificationOpened";
static
NSString
*
const
RNActionTriggered
=
@"notificationActionTriggered"
;
@interface
RNEventEmitter
:
RCTEventEmitter
+
(
instancetype
)
sharedInstance
;
@interface
RNEventEmitter
:
RCTEventEmitter
<
RCTBridgeModule
>
+
(
void
)
sendEvent
:(
NSString
*
)
event
body
:(
NSDictionary
*
)
body
;
...
...
RNNotifications/RNEventEmitter.m
View file @
df53f390
...
...
@@ -14,30 +14,40 @@ RCT_EXPORT_MODULE();
RNActionTriggered
];
}
# pragma mark public
+
(
instancetype
)
sharedInstance
{
static
RNEventEmitter
*
sharedInstance
=
nil
;
static
dispatch_once_t
onceToken
;
dispatch_once
(
&
onceToken
,
^
{
sharedInstance
=
[[
RNEventEmitter
alloc
]
init
];
});
return
sharedInstance
;
-
(
instancetype
)
init
{
self
=
[
super
init
];
for
(
NSString
*
event
in
[
self
supportedEvents
])
{
[
self
addListener
:
event
];
}
return
self
;
}
# pragma mark public
+
(
void
)
sendEvent
:(
NSString
*
)
event
body
:(
NSDictionary
*
)
body
{
[[
self
sharedInstance
]
send
:
event
body
:
body
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
event
object:
self
userInfo:
body
];
}
# pragma mark private
-
(
void
)
send
:(
NSString
*
)
eventName
body
:(
id
)
body
{
if
(
self
.
bridge
==
nil
)
{
return
;
-
(
void
)
startObserving
{
for
(
NSString
*
event
in
[
self
supportedEvents
])
{
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector:
@selector
(
handleNotification
:)
name:
event
object:
nil
];
}
[
self
sendEventWithName
:
eventName
body
:
body
];
}
-
(
void
)
stopObserving
{
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
];
}
-
(
void
)
handleNotification
:(
NSNotification
*
)
notification
{
[
self
sendEventWithName
:
notification
.
name
body
:
notification
.
userInfo
];
}
@end
RNNotifications/RNNotificationEventHandler.h
View file @
df53f390
#import <Foundation/Foundation.h>
@import
UserNotifications
;
#import "RNNotificationsStore.h"
#import "RNEventEmitter.h"
@interface
RNNotificationEventHandler
:
NSObject
...
...
RNNotifications/RNNotifications.h
View file @
df53f390
...
...
@@ -4,11 +4,14 @@
@interface
RNNotifications
:
NSObject
@property
(
nonatomic
,
retain
)
NSDictionary
*
initialNotification
;
+
(
instancetype
)
sharedInstance
;
-
(
void
)
initialize
;
-
(
void
)
didRegisterForRemoteNotificationsWithDeviceToken
:(
id
)
deviceToken
;
-
(
void
)
didFailToRegisterForRemoteNotificationsWithError
:(
NSError
*
)
error
;
-
(
void
)
finishHandleNotificationKey
:(
NSString
*
)
notificationKey
;
//- (void)setBadgeForNotification:(NSDictionary *)notification;
...
...
RNNotifications/RNNotifications.m
View file @
df53f390
...
...
@@ -8,6 +8,14 @@
@implementation
RNNotifications
{
RNNotificationCenterListener
*
_notificationCenterListener
;
RNNotificationEventHandler
*
_notificationEventHandler
;
RNEventEmitter
*
_eventEmitter
;
RNNotificationsStore
*
_store
;
}
-
(
instancetype
)
init
{
self
=
[
super
init
];
_store
=
[
RNNotificationsStore
new
];
return
self
;
}
+
(
instancetype
)
sharedInstance
{
...
...
@@ -21,7 +29,7 @@
}
-
(
void
)
initialize
{
_notificationEventHandler
=
[
RNNotificationEventHandler
new
];
_notificationEventHandler
=
[
[
RNNotificationEventHandler
alloc
]
initWithStore
:
_store
];
_notificationCenterListener
=
[[
RNNotificationCenterListener
alloc
]
initWithNotificationEventHandler
:
_notificationEventHandler
];
}
...
...
@@ -39,4 +47,12 @@
}
}
-
(
void
)
setInitialNotification
:(
NSDictionary
*
)
notification
{
[
_store
setInitialNotification
:
notification
];
}
-
(
void
)
finishHandleNotificationKey
:(
NSString
*
)
notificationKey
{
[
_store
completeAction
:
notificationKey
];
}
@end
RNNotifications/RNNotifications.xcodeproj/project.pbxproj
View file @
df53f390
...
...
@@ -69,8 +69,6 @@
50351F9422CD7FF1000713B3
/* RCTConvert+Notifications.m */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"RCTConvert+Notifications.m"
;
sourceTree
=
"<group>"
;
};
50351F9622CD8604000713B3
/* RNCommandsHandler.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
RNCommandsHandler.h
;
sourceTree
=
"<group>"
;
};
50351F9722CD8604000713B3
/* RNCommandsHandler.m */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
RNCommandsHandler.m
;
sourceTree
=
"<group>"
;
};
508CE7BB22D12B0A00357815
/* Tests.m */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
Tests.m
;
sourceTree
=
"<group>"
;
};
508CE7BD22D12B0A00357815
/* Info.plist */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text.plist.xml
;
path
=
Info.plist
;
sourceTree
=
"<group>"
;
};
508CE7C822D12B2600357815
/* RNNotificationsTests.xctest */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.cfbundle
;
includeInIndex
=
0
;
path
=
RNNotificationsTests.xctest
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
508CE7CA22D12B2600357815
/* RNNotificationsTests.m */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
RNNotificationsTests.m
;
sourceTree
=
"<group>"
;
};
508CE7CC22D12B2600357815
/* Info.plist */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text.plist.xml
;
path
=
Info.plist
;
sourceTree
=
"<group>"
;
};
...
...
@@ -119,15 +117,6 @@
name
=
Products
;
sourceTree
=
"<group>"
;
};
508CE7BA22D12B0A00357815
/* Tests */
=
{
isa
=
PBXGroup
;
children
=
(
508CE7BB22D12B0A00357815
/* Tests.m */
,
508CE7BD22D12B0A00357815
/* Info.plist */
,
);
path
=
Tests
;
sourceTree
=
"<group>"
;
};
508CE7C922D12B2600357815
/* RNNotificationsTests */
=
{
isa
=
PBXGroup
;
children
=
(
...
...
@@ -196,7 +185,6 @@
D8A2F7541CB57F1A002CC8F5
/* RNNotifications.m */
,
50351F9622CD8604000713B3
/* RNCommandsHandler.h */
,
50351F9722CD8604000713B3
/* RNCommandsHandler.m */
,
508CE7BA22D12B0A00357815
/* Tests */
,
508CE7C922D12B2600357815
/* RNNotificationsTests */
,
134814211AA4EA7D00B7C361
/* Products */
,
508CE7C822D12B2600357815
/* RNNotificationsTests.xctest */
,
...
...
RNNotifications/RNPushKitEventListener.m
View file @
df53f390
#import "RNPushKitEventListener.h"
#import "RNEventEmitter.h"
#import "RNUtils.h"
@implementation
RNPushKitEventListener
{
...
...
example/index.ios.js
View file @
df53f390
...
...
@@ -42,6 +42,7 @@ class NotificationsExampleApp extends Component {
};
NotificationsIOS
.
addEventListener
(
'
remoteNotificationsRegistered
'
,
this
.
onPushRegistered
.
bind
(
this
));
NotificationsIOS
.
addEventListener
(
'
remoteNotificationsRegistrationFailed
'
,
this
.
onPushRegisteredFailed
.
bind
(
this
));
NotificationsIOS
.
consumeBackgroundQueue
();
...
...
@@ -56,6 +57,10 @@ class NotificationsExampleApp extends Component {
console
.
log
(
'
Device Token Received:
'
+
deviceToken
);
}
onPushRegisteredFailed
(
error
)
{
console
.
log
(
'
Remote notifiction registration failed:
'
+
error
);
}
onPushKitRegistered
(
deviceToken
)
{
console
.
log
(
'
PushKit Token Received:
'
+
deviceToken
);
}
...
...
example/ios/NotificationsExampleApp/AppDelegate.h
View file @
df53f390
...
...
@@ -9,9 +9,7 @@
#import <UIKit/UIKit.h>
#import <PushKit/PushKit.h>
@interface
AppDelegate
:
UIResponder
<
UIApplicationDelegate
,
PKPushRegistryDelegate
>
@interface
AppDelegate
:
UIResponder
<
UIApplicationDelegate
>
@property
(
nonatomic
,
strong
)
UIWindow
*
window
;
...
...
example/ios/NotificationsExampleApp/AppDelegate.m
View file @
df53f390
...
...
@@ -8,8 +8,7 @@
@implementation
AppDelegate
-
(
BOOL
)
application
:(
UIApplication
*
)
application
didFinishLaunchingWithOptions
:(
NSDictionary
*
)
launchOptions
{
-
(
BOOL
)
application
:(
UIApplication
*
)
application
didFinishLaunchingWithOptions
:(
NSDictionary
*
)
launchOptions
{
NSURL
*
jsCodeLocation
;
jsCodeLocation
=
[[
RCTBundleURLProvider
sharedSettings
]
jsBundleURLForBundleRoot
:
@"index"
fallbackResource
:
nil
];
...
...
@@ -32,14 +31,16 @@
}
// Required to register for notifications
-
(
void
)
application
:(
UIApplication
*
)
application
didRegisterUserNotificationSettings
:(
UIUserNotificationSettings
*
)
notificationSettings
{
-
(
void
)
application
:(
UIApplication
*
)
application
didRegisterUserNotificationSettings
:(
UIUserNotificationSettings
*
)
notificationSettings
{
// [[RNNotifications sharedInstance] didRegisterUserNotificationSettings:notificationSettings];
}
-
(
void
)
application
:(
UIApplication
*
)
application
didRegisterForRemoteNotificationsWithDeviceToken
:(
NSData
*
)
deviceToken
{
-
(
void
)
application
:(
UIApplication
*
)
application
didRegisterForRemoteNotificationsWithDeviceToken
:(
NSData
*
)
deviceToken
{
[[
RNNotifications
sharedInstance
]
didRegisterForRemoteNotificationsWithDeviceToken
:
deviceToken
];
}
-
(
void
)
application
:(
UIApplication
*
)
application
didFailToRegisterForRemoteNotificationsWithError
:(
NSError
*
)
error
{
[[
RNNotifications
sharedInstance
]
didFailToRegisterForRemoteNotificationsWithError
:
error
];
}
@end
example/ios/NotificationsExampleApp/NotificationsExampleApp.entitlements
0 → 100644
View file @
df53f390
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist
version=
"1.0"
>
<dict>
<key>
aps-environment
</key>
<string>
development
</string>
</dict>
</plist>
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