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
903834a4
"...xcshareddata/xcschemes/SmartNotificationsApp.xcscheme" did not exist on "1ee9741b7fc0ad6ef9dd06cbd002956218fc62de"
Commit
903834a4
authored
Apr 15, 2016
by
Lidan Hifi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix interactive notification action coldstart
parent
4392135f
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
103 additions
and
39 deletions
+103
-39
README.md
README.md
+0
-1
RNNotifications/RNNotifications.m
RNNotifications/RNNotifications.m
+30
-5
RNNotifications/RNNotifications.xcodeproj/project.pbxproj
RNNotifications/RNNotifications.xcodeproj/project.pbxproj
+6
-0
RNNotifications/RNNotificationsBridgeQueue.h
RNNotifications/RNNotificationsBridgeQueue.h
+10
-0
RNNotifications/RNNotificationsBridgeQueue.m
RNNotifications/RNNotificationsBridgeQueue.m
+14
-0
example/index.ios.js
example/index.ios.js
+34
-30
index.ios.js
index.ios.js
+8
-2
test/index.ios.spec.js
test/index.ios.spec.js
+1
-1
No files found.
README.md
View file @
903834a4
...
...
@@ -6,5 +6,4 @@ Handle push notifications for your app, including remote and local notifications
## TODO
-
Add permissions management.
-
Add interactive notifications support.
-
Better support of local notifications.
RNNotifications/RNNotifications.m
View file @
903834a4
...
...
@@ -5,6 +5,7 @@
#import "RNNotifications.h"
#import "RCTConvert.h"
#import "RCTUtils.h"
#import "RNNotificationsBridgeQueue.h"
NSString
*
const
RNNotificationCreateAction
=
@"CREATE"
;
NSString
*
const
RNNotificationClearAction
=
@"CLEAR"
;
...
...
@@ -110,6 +111,15 @@ RCT_EXPORT_MODULE()
selector:
@selector
(
handleNotificationActionTriggered
:)
name:
RNNotificationActionTriggered
object:
nil
];
NSDictionary
*
lastActionInfo
=
[
RNNotificationsBridgeQueue
sharedInstance
].
lastAction
;
if
(
lastActionInfo
)
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
RNNotificationActionTriggered
object:
self
userInfo:
lastActionInfo
];
[
RNNotificationsBridgeQueue
sharedInstance
].
lastAction
=
nil
;
}
}
/*
...
...
@@ -146,14 +156,12 @@ RCT_EXPORT_MODULE()
+
(
void
)
application
:(
UIApplication
*
)
application
handleActionWithIdentifier
:(
NSString
*
)
identifier
forLocalNotification
:(
UILocalNotification
*
)
notification
withResponseInfo
:(
NSDictionary
*
)
responseInfo
completionHandler
:(
void
(
^
)())
completionHandler
{
[
self
emitNotificationActionForIdentifier
:
identifier
responseInfo
:
responseInfo
userInfo
:
notification
.
userInfo
];
completionHandler
();
[
self
emitNotificationActionForIdentifier
:
identifier
responseInfo
:
responseInfo
userInfo
:
notification
.
userInfo
completionHandler
:
completionHandler
];
}
+
(
void
)
application
:(
UIApplication
*
)
application
handleActionWithIdentifier
:(
NSString
*
)
identifier
forRemoteNotification
:(
NSDictionary
*
)
userInfo
withResponseInfo
:(
NSDictionary
*
)
responseInfo
completionHandler
:(
void
(
^
)())
completionHandler
{
[
self
emitNotificationActionForIdentifier
:
identifier
responseInfo
:
responseInfo
userInfo
:
userInfo
];
completionHandler
();
[
self
emitNotificationActionForIdentifier
:
identifier
responseInfo
:
responseInfo
userInfo
:
userInfo
completionHandler
:
completionHandler
];
}
/*
...
...
@@ -270,7 +278,7 @@ RCT_EXPORT_MODULE()
[[
UIApplication
sharedApplication
]
registerUserNotificationSettings
:
settings
];
}
+
(
void
)
emitNotificationActionForIdentifier
:(
NSString
*
)
identifier
responseInfo
:(
NSDictionary
*
)
responseInfo
userInfo
:(
NSDictionary
*
)
userInfo
+
(
void
)
emitNotificationActionForIdentifier
:(
NSString
*
)
identifier
responseInfo
:(
NSDictionary
*
)
responseInfo
userInfo
:(
NSDictionary
*
)
userInfo
completionHandler
:(
void
(
^
)())
completionHandler
{
NSMutableDictionary
*
info
=
[[
NSMutableDictionary
alloc
]
initWithDictionary
:@{
@"identifier"
:
identifier
}];
...
...
@@ -289,6 +297,9 @@ RCT_EXPORT_MODULE()
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
RNNotificationActionTriggered
object:
self
userInfo:
info
];
[
RNNotificationsBridgeQueue
sharedInstance
].
lastAction
=
info
;
[
RNNotificationsBridgeQueue
sharedInstance
].
lastCompletionHandler
=
completionHandler
;
}
/*
...
...
@@ -322,4 +333,18 @@ RCT_EXPORT_METHOD(updateNotificationCategories:(NSArray *)json)
[
RNNotifications
updateNotificationCategories
:
json
];
}
RCT_EXPORT_METHOD
(
log
:
(
NSString
*
)
message
)
{
NSLog
(
message
);
}
RCT_EXPORT_METHOD
(
completionHandler
)
{
void
(
^
completionHandler
)()
=
[
RNNotificationsBridgeQueue
sharedInstance
].
lastCompletionHandler
;
if
(
completionHandler
)
{
completionHandler
();
[
RNNotificationsBridgeQueue
sharedInstance
].
lastCompletionHandler
=
nil
;
}
}
@end
RNNotifications/RNNotifications.xcodeproj/project.pbxproj
View file @
903834a4
...
...
@@ -7,6 +7,7 @@
objects
=
{
/* Begin PBXBuildFile section */
D85B37451CC05A0900DE9EB6
/* RNNotificationsBridgeQueue.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
D85B37441CC05A0900DE9EB6
/* RNNotificationsBridgeQueue.m */
;
};
D8A2F7551CB57F1A002CC8F5
/* RNNotifications.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
D8A2F7541CB57F1A002CC8F5
/* RNNotifications.m */
;
};
/* End PBXBuildFile section */
...
...
@@ -24,6 +25,8 @@
/* Begin PBXFileReference section */
134814201AA4EA6300B7C361
/* libRNNotifications.a */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
archive.ar
;
includeInIndex
=
0
;
path
=
libRNNotifications.a
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
D85B37441CC05A0900DE9EB6
/* RNNotificationsBridgeQueue.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
RNNotificationsBridgeQueue.m
;
sourceTree
=
"<group>"
;
};
D85B37461CC05A1200DE9EB6
/* RNNotificationsBridgeQueue.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
RNNotificationsBridgeQueue.h
;
sourceTree
=
"<group>"
;
};
D8A2F7541CB57F1A002CC8F5
/* RNNotifications.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
RNNotifications.m
;
sourceTree
=
"<group>"
;
};
D8A2F7561CB57F28002CC8F5
/* RNNotifications.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
RNNotifications.h
;
sourceTree
=
"<group>"
;
};
/* End PBXFileReference section */
...
...
@@ -50,6 +53,8 @@
58B511D21A9E6C8500147676
=
{
isa
=
PBXGroup
;
children
=
(
D85B37461CC05A1200DE9EB6
/* RNNotificationsBridgeQueue.h */
,
D85B37441CC05A0900DE9EB6
/* RNNotificationsBridgeQueue.m */
,
D8A2F7561CB57F28002CC8F5
/* RNNotifications.h */
,
D8A2F7541CB57F1A002CC8F5
/* RNNotifications.m */
,
134814211AA4EA7D00B7C361
/* Products */
,
...
...
@@ -113,6 +118,7 @@
buildActionMask
=
2147483647
;
files
=
(
D8A2F7551CB57F1A002CC8F5
/* RNNotifications.m in Sources */
,
D85B37451CC05A0900DE9EB6
/* RNNotificationsBridgeQueue.m in Sources */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
};
...
...
RNNotifications/RNNotificationsBridgeQueue.h
0 → 100644
View file @
903834a4
#import <Foundation/Foundation.h>
@interface
RNNotificationsBridgeQueue
:
NSObject
@property
(
nonatomic
,
retain
)
NSDictionary
*
lastAction
;
@property
(
nonatomic
,
copy
)
void
(
^
lastCompletionHandler
)();
+
(
nonnull
instancetype
)
sharedInstance
;
@end
\ No newline at end of file
RNNotifications/RNNotificationsBridgeQueue.m
0 → 100644
View file @
903834a4
#import "RNNotificationsBridgeQueue.h"
@implementation
RNNotificationsBridgeQueue
+
(
nonnull
instancetype
)
sharedInstance
{
static
RNNotificationsBridgeQueue
*
sharedInstance
=
nil
;
static
dispatch_once_t
onceToken
;
dispatch_once
(
&
onceToken
,
^
{
sharedInstance
=
[
self
new
];
});
return
sharedInstance
;
}
@end
\ No newline at end of file
example/index.ios.js
View file @
903834a4
...
...
@@ -14,6 +14,38 @@ import React, {
import
NotificationsIOS
,
{
NotificationAction
,
NotificationCategory
}
from
'
react-native-notifications
'
;
let
upvoteAction
=
new
NotificationAction
({
activationMode
:
"
background
"
,
title
:
String
.
fromCodePoint
(
0x1F44D
),
identifier
:
"
UPVOTE_ACTION
"
},
(
action
,
completed
)
=>
{
NotificationsIOS
.
log
(
"
ACTION RECEIVED
"
);
NotificationsIOS
.
log
(
JSON
.
stringify
(
action
));
completed
();
});
let
replyAction
=
new
NotificationAction
({
activationMode
:
"
background
"
,
title
:
"
Reply
"
,
behavior
:
"
textInput
"
,
authenticationRequired
:
true
,
identifier
:
"
REPLY_ACTION
"
},
(
action
,
completed
)
=>
{
console
.
log
(
"
ACTION RECEIVED
"
);
console
.
log
(
action
);
completed
();
});
let
cat
=
new
NotificationCategory
({
identifier
:
"
SOME_CATEGORY
"
,
actions
:
[
upvoteAction
,
replyAction
],
context
:
"
default
"
});
NotificationsIOS
.
setCategories
([
cat
]);
class
NotificationsExampleApp
extends
Component
{
constructor
()
{
...
...
@@ -26,35 +58,7 @@ class NotificationsExampleApp extends Component {
}
componentDidMount
()
{
PushNotificationIOS
.
requestPermissions
();
let
upvoteAction
=
new
NotificationAction
({
activationMode
:
"
background
"
,
title
:
String
.
fromCodePoint
(
0x1F44D
),
identifier
:
"
UPVOTE_ACTION
"
},
(
action
)
=>
{
console
.
log
(
"
ACTION RECEIVED
"
);
console
.
log
(
action
);
});
let
replyAction
=
new
NotificationAction
({
activationMode
:
"
background
"
,
title
:
"
Reply
"
,
behavior
:
"
textInput
"
,
authenticationRequired
:
true
,
identifier
:
"
REPLY_ACTION
"
},
(
action
)
=>
{
console
.
log
(
"
ACTION RECEIVED
"
);
console
.
log
(
action
);
});
let
cat
=
new
NotificationCategory
({
identifier
:
"
SOME_CATEGORY
"
,
actions
:
[
upvoteAction
,
replyAction
],
context
:
"
default
"
});
NotificationsIOS
.
setCategories
([
cat
]);
// PushNotificationIOS.requestPermissions();
}
onPushRegistered
(
deviceToken
)
{
...
...
@@ -94,7 +98,7 @@ class NotificationsExampleApp extends Component {
NotificationsIOS
.
removeEventListener
(
'
notificationReceivedForeground
'
,
this
.
onNotificationReceivedForeground
.
bind
(
this
));
NotificationsIOS
.
removeEventListener
(
'
notificationReceivedBackground
'
,
this
.
onNotificationReceivedBackground
.
bind
(
this
));
NotificationsIOS
.
removeEventListener
(
'
notificationOpened
'
,
this
.
onNotificationOpened
.
bind
(
this
));
NotificationsIOS
.
resetCategories
();
//
NotificationsIOS.resetCategories();
}
_onNotification
(
notification
)
{
...
...
index.ios.js
View file @
903834a4
...
...
@@ -76,7 +76,9 @@ export default class NotificationsIOS {
let
actionHandler
=
_actionHandlers
.
get
(
action
.
identifier
);
if
(
actionHandler
)
{
actionHandler
(
action
);
action
.
notification
=
new
IOSNotification
(
action
.
notification
);
actionHandler
(
action
,
()
=>
{
NativeRNNotifications
.
completionHandler
();
});
}
}
...
...
@@ -89,7 +91,7 @@ export default class NotificationsIOS {
if
(
categories
)
{
// subscribe once for all actions
_actionListener
=
NativeAppEventEmitter
.
addListener
(
DEVICE_NOTIFICATION_ACTION_RECEIVED
,
this
.
_actionHandlerDispatcher
);
_actionListener
=
NativeAppEventEmitter
.
addListener
(
DEVICE_NOTIFICATION_ACTION_RECEIVED
,
this
.
_actionHandlerDispatcher
.
bind
(
this
)
);
notificationCategories
=
categories
.
map
(
category
=>
{
return
Object
.
assign
({},
category
.
options
,
{
...
...
@@ -117,4 +119,8 @@ export default class NotificationsIOS {
_actionHandlers
.
clear
();
}
static
log
(
message
)
{
NativeRNNotifications
.
log
(
message
);
}
}
test/index.ios.spec.js
View file @
903834a4
...
...
@@ -149,7 +149,7 @@ describe("NotificationsIOS", () => {
NotificationsIOS
.
setCategories
([
someCategory
]);
expect
(
nativeAppAddEventListener
).
to
.
have
.
been
.
calledOnce
;
expect
(
nativeAppAddEventListener
).
to
.
have
.
been
.
calledWith
(
"
notificationActionReceived
"
,
NotificationsIOS
.
_actionHandlerDispatcher
);
expect
(
nativeAppAddEventListener
).
to
.
have
.
been
.
calledWith
(
"
notificationActionReceived
"
,
sinon
.
match
.
func
);
});
});
...
...
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