Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-fcm
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
ym
react-native-fcm
Commits
26132aae
Commit
26132aae
authored
Feb 12, 2018
by
Libin Lu
Committed by
GitHub
Feb 12, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #792 from evollu/pending-notif
hold notification when app is bootstrapping
parents
51ea457d
14c578d3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
43 deletions
+58
-43
ios/RNFIRMessaging.m
ios/RNFIRMessaging.m
+58
-43
No files found.
ios/RNFIRMessaging.m
View file @
26132aae
...
...
@@ -217,14 +217,15 @@ RCT_MULTI_ENUM_CONVERTER(UNNotificationCategoryOptions, (@{
@end
static
NSDictionary
*
initialNotificationActionResponse
;
@interface
RNFIRMessaging
()
@property
(
nonatomic
,
strong
)
NSMutableDictionary
*
notificationCallbacks
;
@end
@implementation
RNFIRMessaging
static
bool
jsHandlerRegistered
;
static
NSMutableArray
*
pendingNotifications
;
RCT_EXPORT_MODULE
();
-
(
NSArray
<
NSString
*>
*
)
supportedEvents
{
...
...
@@ -239,14 +240,14 @@ RCT_EXPORT_MODULE();
NSMutableDictionary
*
data
=
[[
NSMutableDictionary
alloc
]
initWithDictionary
:
userInfo
];
[
data
setValue
:
@"remote_notification"
forKey
:
@"_notificationType"
];
[
data
setValue
:
@
(
RCTSharedApplication
().
applicationState
==
UIApplicationStateInactive
)
forKey
:
@"opened_from_tray"
];
[
[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
FCMNotificationReceived
object
:
self
userInfo
:
@{
@"data"
:
data
,
@"completionHandler"
:
completionHandler
}];
[
self
sendNotificationEventWhenAvailable
:@{
@"data"
:
data
,
@"completionHandler"
:
completionHandler
}];
}
+
(
void
)
didReceiveLocalNotification
:(
UILocalNotification
*
)
notification
{
NSMutableDictionary
*
data
=
[[
NSMutableDictionary
alloc
]
initWithDictionary
:
notification
.
userInfo
];
[
data
setValue
:
@"local_notification"
forKey
:
@"_notificationType"
];
[
data
setValue
:
@
(
RCTSharedApplication
().
applicationState
==
UIApplicationStateInactive
)
forKey
:
@"opened_from_tray"
];
[
[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
FCMNotificationReceived
object
:
self
userInfo
:
@{
@"data"
:
data
}];
[
self
sendNotificationEventWhenAvailable
:@{
@"data"
:
data
}];
}
+
(
void
)
didReceiveNotificationResponse
:(
UNNotificationResponse
*
)
response
withCompletionHandler
:(
nonnull
RCTNotificationResponseCallback
)
completionHandler
...
...
@@ -263,22 +264,28 @@ RCT_EXPORT_MODULE();
}
NSDictionary
*
userInfo
=
@{
@"data"
:
data
,
@"completionHandler"
:
completionHandler
};
[
self
sendNotificationEventWhenAvailable
:
userInfo
];
static
dispatch_once_t
onceToken
;
dispatch_once
(
&
onceToken
,
^
{
if
(
data
[
@"_actionIdentifier"
]
&&
!
[
data
[
@"_actionIdentifier"
]
isEqualToString
:
UNNotificationDefaultActionIdentifier
])
{
initialNotificationActionResponse
=
userInfo
;
}
});
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
FCMNotificationReceived
object
:
self
userInfo
:
userInfo
];
}
+
(
void
)
willPresentNotification
:(
UNNotification
*
)
notification
withCompletionHandler
:(
nonnull
RCTWillPresentNotificationCallback
)
completionHandler
{
NSMutableDictionary
*
data
=
[[
NSMutableDictionary
alloc
]
initWithDictionary
:
notification
.
request
.
content
.
userInfo
];
[
data
setValue
:
@"will_present_notification"
forKey
:
@"_notificationType"
];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
FCMNotificationReceived
object
:
self
userInfo
:
@{
@"data"
:
data
,
@"completionHandler"
:
completionHandler
}];
[
self
sendNotificationEventWhenAvailable
:@{
@"data"
:
data
,
@"completionHandler"
:
completionHandler
}];
}
+
(
void
)
sendNotificationEventWhenAvailable
:(
NSDictionary
*
)
data
{
if
(
!
jsHandlerRegistered
){
// JS hasn't registered callback yet. hold on that
if
(
!
pendingNotifications
){
pendingNotifications
=
[
NSMutableArray
array
];
}
[
pendingNotifications
addObject
:
data
];
}
else
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
FCMNotificationReceived
object
:
self
userInfo
:
data
];
}
}
-
(
void
)
dealloc
...
...
@@ -288,6 +295,7 @@ RCT_EXPORT_MODULE();
-
(
instancetype
)
init
{
self
=
[
super
init
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector:
@selector
(
handleNotificationReceived
:)
name:
FCMNotificationReceived
...
...
@@ -309,16 +317,25 @@ RCT_EXPORT_MODULE();
dispatch_async
(
dispatch_get_main_queue
(),
^
{
[[
FIRMessaging
messaging
]
setDelegate
:
self
];
});
return
self
;
}
-
(
void
)
addListener
:(
NSString
*
)
eventName
{
if
([
super
respondsToSelector
:
@selector
(
addListener
:)]){
[
super
addListener
:
eventName
];
if
([
eventName
isEqualToString
:
FCMNotificationReceived
])
{
static
dispatch_once_t
onceToken
;
dispatch_once
(
&
onceToken
,
^
{
jsHandlerRegistered
=
true
;
for
(
NSDictionary
*
data
in
pendingNotifications
)
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
FCMNotificationReceived
object
:
self
userInfo
:
data
];
}
if
([
eventName
isEqualToString
:
FCMNotificationReceived
]
&&
initialNotificationActionResponse
)
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
FCMNotificationReceived
object
:
self
userInfo
:
[
initialNotificationActionResponse
copy
]];
[
pendingNotifications
removeAllObjects
];
});
}
}
...
...
@@ -336,6 +353,7 @@ RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve rejecte
{
NSDictionary
*
initialNotif
;
NSDictionary
*
localUserInfo
=
[[
self
.
bridge
.
launchOptions
[
UIApplicationLaunchOptionsLocalNotificationKey
]
userInfo
]
mutableCopy
];
NSDictionary
*
remoteUserInfo
=
[
self
.
bridge
.
launchOptions
[
UIApplicationLaunchOptionsRemoteNotificationKey
]
mutableCopy
];
if
(
localUserInfo
){
initialNotif
=
localUserInfo
;
...
...
@@ -350,6 +368,8 @@ RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve rejecte
}
}
RCT_EXPORT_METHOD
(
getAPNSToken
:
(
RCTPromiseResolveBlock
)
resolve
rejecter
:
(
RCTPromiseRejectBlock
)
reject
)
{
NSData
*
deviceToken
=
[
FIRMessaging
messaging
].
APNSToken
;
...
...
@@ -655,12 +675,7 @@ RCT_EXPORT_METHOD(finishNotificationResponse: (NSString *)completionHandlerId){
self
.
notificationCallbacks
[
completionHandlerId
]
=
completionHandler
;
data
[
@"_completionHandlerId"
]
=
completionHandlerId
;
}
[
self
sendEventWithName
:
FCMNotificationReceived
body
:
data
];
if
(
initialNotificationActionResponse
)
{
initialNotificationActionResponse
=
nil
;
}
}
-
(
void
)
sendDataMessageFailure
:(
NSNotification
*
)
notification
...
...
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