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
25c9c400
Commit
25c9c400
authored
May 09, 2016
by
Lidan Hifi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug- trigger notification opened event on app launch
parent
97ed9e39
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
29 deletions
+54
-29
RNNotifications/RNNotifications.m
RNNotifications/RNNotifications.m
+38
-20
RNNotifications/RNNotificationsBridgeQueue.h
RNNotifications/RNNotificationsBridgeQueue.h
+3
-0
RNNotifications/RNNotificationsBridgeQueue.m
RNNotifications/RNNotificationsBridgeQueue.m
+8
-8
example/ios/NotificationsExampleApp.xcodeproj/project.pbxproj
...ple/ios/NotificationsExampleApp.xcodeproj/project.pbxproj
+4
-0
example/ios/NotificationsExampleApp/AppDelegate.m
example/ios/NotificationsExampleApp/AppDelegate.m
+1
-1
No files found.
RNNotifications/RNNotifications.m
View file @
25c9c400
...
@@ -142,6 +142,9 @@ RCT_EXPORT_MODULE()
...
@@ -142,6 +142,9 @@ RCT_EXPORT_MODULE()
selector:
@selector
(
handleNotificationActionTriggered
:)
selector:
@selector
(
handleNotificationActionTriggered
:)
name:
RNNotificationActionTriggered
name:
RNNotificationActionTriggered
object:
nil
];
object:
nil
];
[
RNNotificationsBridgeQueue
sharedInstance
].
openedRemoteNotification
=
[
_bridge
.
launchOptions
objectForKey
:
UIApplicationLaunchOptionsRemoteNotificationKey
];
[
RNNotificationsBridgeQueue
sharedInstance
].
openedLocalNotification
=
[
_bridge
.
launchOptions
objectForKey
:
UIApplicationLaunchOptionsLocalNotificationKey
];
}
}
/*
/*
...
@@ -165,15 +168,22 @@ RCT_EXPORT_MODULE()
...
@@ -165,15 +168,22 @@ RCT_EXPORT_MODULE()
{
{
UIApplicationState
state
=
[
UIApplication
sharedApplication
].
applicationState
;
UIApplicationState
state
=
[
UIApplication
sharedApplication
].
applicationState
;
if
(
state
==
UIApplicationStateActive
)
{
if
([
RNNotificationsBridgeQueue
sharedInstance
].
jsIsReady
==
YES
)
{
// Notification received foreground
// JS thread is ready, push the notification to the bridge
[
self
didReceiveNotificationOnForegroundState
:
notification
];
}
else
if
(
state
==
UIApplicationStateInactive
)
{
if
(
state
==
UIApplicationStateActive
)
{
// Notification opened
// Notification received foreground
[
self
didNotificationOpen
:
notification
];
[
self
didReceiveNotificationOnForegroundState
:
notification
];
}
else
if
(
state
==
UIApplicationStateInactive
)
{
// Notification opened
[
self
didNotificationOpen
:
notification
];
}
else
{
// Notification received background
[
self
didReceiveNotificationOnBackgroundState
:
notification
];
}
}
else
{
}
else
{
//
Notification received background
//
JS thread is not ready - store it in the native notifications queue
[
self
didReceiveNotificationOnBackgroundState
:
notification
];
[
[
RNNotificationsBridgeQueue
sharedInstance
]
postNotification
:
notification
];
}
}
}
}
...
@@ -231,14 +241,9 @@ RCT_EXPORT_MODULE()
...
@@ -231,14 +241,9 @@ RCT_EXPORT_MODULE()
}
}
}
}
// if Js thread is ready- post notification to bridge. otherwise- post it to the bridge queue
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
RNNotificationReceivedBackground
if
([
RNNotificationsBridgeQueue
sharedInstance
].
jsIsReady
==
YES
)
{
object:
self
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
RNNotificationReceivedBackground
userInfo:
notification
];
object:
self
userInfo:
notification
];
}
else
{
[[
RNNotificationsBridgeQueue
sharedInstance
]
postNotification
:
notification
];
}
}
}
+
(
void
)
didNotificationOpen
:(
NSDictionary
*
)
notification
+
(
void
)
didNotificationOpen
:(
NSDictionary
*
)
notification
...
@@ -450,19 +455,32 @@ RCT_EXPORT_METHOD(backgroundTimeRemaining:(RCTResponseSenderBlock)callback)
...
@@ -450,19 +455,32 @@ RCT_EXPORT_METHOD(backgroundTimeRemaining:(RCTResponseSenderBlock)callback)
RCT_EXPORT_METHOD
(
consumeBackgroundQueue
)
RCT_EXPORT_METHOD
(
consumeBackgroundQueue
)
{
{
// Mark JS Thread as ready
[
RNNotificationsBridgeQueue
sharedInstance
].
jsIsReady
=
YES
;
// Push actions to JS
[[
RNNotificationsBridgeQueue
sharedInstance
]
consumeActionsQueue
:
^
(
NSDictionary
*
action
)
{
[[
RNNotificationsBridgeQueue
sharedInstance
]
consumeActionsQueue
:
^
(
NSDictionary
*
action
)
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
RNNotificationActionTriggered
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
RNNotificationActionTriggered
object:
self
object:
self
userInfo:
action
];
userInfo:
action
];
}];
}];
// Push background notifications to JS
[[
RNNotificationsBridgeQueue
sharedInstance
]
consumeNotificationsQueue
:
^
(
NSDictionary
*
notification
)
{
[[
RNNotificationsBridgeQueue
sharedInstance
]
consumeNotificationsQueue
:
^
(
NSDictionary
*
notification
)
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
RNNotificationReceivedBackground
[
RNNotifications
didReceiveRemoteNotification
:
notification
];
object:
self
userInfo:
notification
];
}];
}];
[
RNNotificationsBridgeQueue
sharedInstance
].
jsIsReady
=
YES
;
// Push opened local notifications
NSDictionary
*
openedLocalNotification
=
[
RNNotificationsBridgeQueue
sharedInstance
].
openedLocalNotification
;
if
(
openedLocalNotification
)
{
[
RNNotifications
didNotificationOpen
:
openedLocalNotification
];
}
// Push opened remote notifications
NSDictionary
*
openedRemoteNotification
=
[
RNNotificationsBridgeQueue
sharedInstance
].
openedRemoteNotification
;
if
(
openedRemoteNotification
)
{
[
RNNotifications
didNotificationOpen
:
openedRemoteNotification
];
}
}
}
RCT_EXPORT_METHOD
(
localNotification
:
(
NSDictionary
*
)
notification
)
RCT_EXPORT_METHOD
(
localNotification
:
(
NSDictionary
*
)
notification
)
...
...
RNNotifications/RNNotificationsBridgeQueue.h
View file @
25c9c400
...
@@ -3,8 +3,11 @@
...
@@ -3,8 +3,11 @@
@interface
RNNotificationsBridgeQueue
:
NSObject
@interface
RNNotificationsBridgeQueue
:
NSObject
@property
BOOL
jsIsReady
;
@property
BOOL
jsIsReady
;
@property
NSDictionary
*
openedRemoteNotification
;
@property
NSDictionary
*
openedLocalNotification
;
+
(
nonnull
instancetype
)
sharedInstance
;
+
(
nonnull
instancetype
)
sharedInstance
;
-
(
void
)
postAction
:(
NSDictionary
*
)
action
withCompletionKey
:(
NSString
*
)
completionKey
andCompletionHandler
:(
void
(
^
)())
completionHandler
;
-
(
void
)
postAction
:(
NSDictionary
*
)
action
withCompletionKey
:(
NSString
*
)
completionKey
andCompletionHandler
:(
void
(
^
)())
completionHandler
;
-
(
void
)
postNotification
:(
NSDictionary
*
)
notification
;
-
(
void
)
postNotification
:(
NSDictionary
*
)
notification
;
...
...
RNNotifications/RNNotificationsBridgeQueue.m
View file @
25c9c400
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
@implementation
RNNotificationsBridgeQueue
@implementation
RNNotificationsBridgeQueue
NSMutableArray
<
NSDictionary
*>*
actionsQueue
;
NSMutableArray
<
NSDictionary
*>*
actionsQueue
;
NSMutableArray
<
NSDictionary
*>*
backgroundN
otificationsQueue
;
NSMutableArray
<
NSDictionary
*>*
n
otificationsQueue
;
NSMutableDictionary
*
actionCompletionHandlers
;
NSMutableDictionary
*
actionCompletionHandlers
;
+
(
nonnull
instancetype
)
sharedInstance
{
+
(
nonnull
instancetype
)
sharedInstance
{
...
@@ -19,7 +19,7 @@ NSMutableDictionary* actionCompletionHandlers;
...
@@ -19,7 +19,7 @@ NSMutableDictionary* actionCompletionHandlers;
-
(
instancetype
)
init
-
(
instancetype
)
init
{
{
actionsQueue
=
[
NSMutableArray
new
];
actionsQueue
=
[
NSMutableArray
new
];
backgroundN
otificationsQueue
=
[
NSMutableArray
new
];
n
otificationsQueue
=
[
NSMutableArray
new
];
actionCompletionHandlers
=
[
NSMutableDictionary
new
];
actionCompletionHandlers
=
[
NSMutableDictionary
new
];
self
.
jsIsReady
=
NO
;
self
.
jsIsReady
=
NO
;
...
@@ -28,16 +28,16 @@ NSMutableDictionary* actionCompletionHandlers;
...
@@ -28,16 +28,16 @@ NSMutableDictionary* actionCompletionHandlers;
-
(
void
)
postNotification
:(
NSDictionary
*
)
notification
-
(
void
)
postNotification
:(
NSDictionary
*
)
notification
{
{
if
(
!
backgroundN
otificationsQueue
)
return
;
if
(
!
n
otificationsQueue
)
return
;
[
backgroundN
otificationsQueue
insertObject
:
notification
atIndex
:
0
];
[
n
otificationsQueue
insertObject
:
notification
atIndex
:
0
];
}
}
-
(
NSDictionary
*
)
dequeueSingleNotification
-
(
NSDictionary
*
)
dequeueSingleNotification
{
{
if
(
!
backgroundNotificationsQueue
||
backgroundN
otificationsQueue
.
count
==
0
)
return
nil
;
if
(
!
notificationsQueue
||
n
otificationsQueue
.
count
==
0
)
return
nil
;
NSDictionary
*
notification
=
[
backgroundN
otificationsQueue
lastObject
];
NSDictionary
*
notification
=
[
n
otificationsQueue
lastObject
];
[
backgroundN
otificationsQueue
removeLastObject
];
[
n
otificationsQueue
removeLastObject
];
return
notification
;
return
notification
;
}
}
...
@@ -50,7 +50,7 @@ NSMutableDictionary* actionCompletionHandlers;
...
@@ -50,7 +50,7 @@ NSMutableDictionary* actionCompletionHandlers;
block
(
notification
);
block
(
notification
);
}
}
backgroundN
otificationsQueue
=
nil
;
n
otificationsQueue
=
nil
;
}
}
-
(
void
)
postAction
:(
NSDictionary
*
)
action
withCompletionKey
:(
NSString
*
)
completionKey
andCompletionHandler
:(
void
(
^
)())
completionHandler
-
(
void
)
postAction
:(
NSDictionary
*
)
action
withCompletionKey
:(
NSString
*
)
completionKey
andCompletionHandler
:(
void
(
^
)())
completionHandler
...
...
example/ios/NotificationsExampleApp.xcodeproj/project.pbxproj
View file @
25c9c400
...
@@ -691,6 +691,7 @@
...
@@ -691,6 +691,7 @@
OTHER_LDFLAGS
=
"-ObjC"
;
OTHER_LDFLAGS
=
"-ObjC"
;
PRODUCT_BUNDLE_IDENTIFIER
=
"com.wix.smart-notifications-test-app"
;
PRODUCT_BUNDLE_IDENTIFIER
=
"com.wix.smart-notifications-test-app"
;
PRODUCT_NAME
=
NotificationsExampleApp
;
PRODUCT_NAME
=
NotificationsExampleApp
;
PROVISIONING_PROFILE
=
""
;
};
};
name
=
Debug
;
name
=
Debug
;
};
};
...
@@ -710,6 +711,7 @@
...
@@ -710,6 +711,7 @@
OTHER_LDFLAGS
=
"-ObjC"
;
OTHER_LDFLAGS
=
"-ObjC"
;
PRODUCT_BUNDLE_IDENTIFIER
=
"com.wix.smart-notifications-test-app"
;
PRODUCT_BUNDLE_IDENTIFIER
=
"com.wix.smart-notifications-test-app"
;
PRODUCT_NAME
=
NotificationsExampleApp
;
PRODUCT_NAME
=
NotificationsExampleApp
;
PROVISIONING_PROFILE
=
""
;
};
};
name
=
Release
;
name
=
Release
;
};
};
...
@@ -730,6 +732,7 @@
...
@@ -730,6 +732,7 @@
CLANG_WARN_OBJC_ROOT_CLASS
=
YES_ERROR
;
CLANG_WARN_OBJC_ROOT_CLASS
=
YES_ERROR
;
CLANG_WARN_UNREACHABLE_CODE
=
YES
;
CLANG_WARN_UNREACHABLE_CODE
=
YES
;
CLANG_WARN__DUPLICATE_METHOD_MATCH
=
YES
;
CLANG_WARN__DUPLICATE_METHOD_MATCH
=
YES
;
CODE_SIGN_IDENTITY
=
"iPhone Developer"
;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]"
=
"iPhone Developer"
;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]"
=
"iPhone Developer"
;
COPY_PHASE_STRIP
=
NO
;
COPY_PHASE_STRIP
=
NO
;
ENABLE_STRICT_OBJC_MSGSEND
=
YES
;
ENABLE_STRICT_OBJC_MSGSEND
=
YES
;
...
@@ -777,6 +780,7 @@
...
@@ -777,6 +780,7 @@
CLANG_WARN_OBJC_ROOT_CLASS
=
YES_ERROR
;
CLANG_WARN_OBJC_ROOT_CLASS
=
YES_ERROR
;
CLANG_WARN_UNREACHABLE_CODE
=
YES
;
CLANG_WARN_UNREACHABLE_CODE
=
YES
;
CLANG_WARN__DUPLICATE_METHOD_MATCH
=
YES
;
CLANG_WARN__DUPLICATE_METHOD_MATCH
=
YES
;
CODE_SIGN_IDENTITY
=
"iPhone Developer"
;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]"
=
"iPhone Developer"
;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]"
=
"iPhone Developer"
;
COPY_PHASE_STRIP
=
YES
;
COPY_PHASE_STRIP
=
YES
;
ENABLE_NS_ASSERTIONS
=
NO
;
ENABLE_NS_ASSERTIONS
=
NO
;
...
...
example/ios/NotificationsExampleApp/AppDelegate.m
View file @
25c9c400
...
@@ -33,7 +33,7 @@
...
@@ -33,7 +33,7 @@
* on the same Wi-Fi network.
* on the same Wi-Fi network.
*/
*/
jsCodeLocation
=
[
NSURL
URLWithString
:
@"http://1
92.168.1.15
:8081/index.ios.bundle?platform=ios&dev=true"
];
jsCodeLocation
=
[
NSURL
URLWithString
:
@"http://1
72.31.9.91
:8081/index.ios.bundle?platform=ios&dev=true"
];
/**
/**
* OPTION 2
* OPTION 2
...
...
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