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
2aaaad99
Commit
2aaaad99
authored
Feb 15, 2018
by
Lucas Gladding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added method for getting the current badge count.
parent
28a28117
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
1 deletion
+28
-1
RNNotifications/RNNotifications.m
RNNotifications/RNNotifications.m
+6
-0
docs/advancedIos.md
docs/advancedIos.md
+6
-1
index.ios.js
index.ios.js
+4
-0
test/index.ios.spec.js
test/index.ios.spec.js
+12
-0
No files found.
RNNotifications/RNNotifications.m
View file @
2aaaad99
...
...
@@ -533,6 +533,12 @@ RCT_EXPORT_METHOD(registerPushKit)
[
RNNotifications
registerPushKit
];
}
RCT_EXPORT_METHOD
(
getBadgesCount
:
(
RCTResponseSenderBlock
)
callback
)
{
NSInteger
count
=
[
UIApplication
sharedApplication
].
applicationIconBadgeNumber
;
callback
(@[
[
NSNumber
numberWithInteger
:
count
]
]);
}
RCT_EXPORT_METHOD
(
setBadgesCount
:
(
int
)
count
)
{
[[
UIApplication
sharedApplication
]
setApplicationIconBadgeNumber
:
count
];
...
...
docs/advancedIos.md
View file @
2aaaad99
...
...
@@ -260,7 +260,12 @@ The [example app](https://github.com/wix/react-native-notifications/tree/master/
-
`minimal`
- Displays up tp 2 actions (minimal UI).
#### Set application icon badges count (iOS only)
#### Get and set application icon badges count (iOS only)
Get the current number:
```
javascript
NotificationsIOS
.
getBadgesCount
((
count
)
=>
console
.
log
(
count
));
```
Set to specific number:
```
javascript
...
...
index.ios.js
View file @
2aaaad99
...
...
@@ -160,6 +160,10 @@ export default class NotificationsIOS {
_actionHandlers
.
clear
();
}
static
getBadgesCount
(
callback
:
Function
)
{
NativeRNNotifications
.
getBadgesCount
(
callback
);
}
static
setBadgesCount
(
count
:
number
)
{
NativeRNNotifications
.
setBadgesCount
(
count
);
}
...
...
test/index.ios.spec.js
View file @
2aaaad99
...
...
@@ -28,6 +28,7 @@ describe("NotificationsIOS", () => {
nativeLocalNotification
,
nativeCancelLocalNotification
,
nativeCancelAllLocalNotifications
,
nativeGetBadgesCount
,
nativeSetBadgesCount
,
nativeIsRegisteredForRemoteNotifications
,
nativeCheckPermissions
,
...
...
@@ -54,6 +55,7 @@ describe("NotificationsIOS", () => {
nativeLocalNotification
=
sinon
.
spy
();
nativeCancelLocalNotification
=
sinon
.
spy
();
nativeCancelAllLocalNotifications
=
sinon
.
spy
();
nativeGetBadgesCount
=
sinon
.
spy
();
nativeSetBadgesCount
=
sinon
.
spy
();
nativeIsRegisteredForRemoteNotifications
=
sinon
.
spy
();
nativeCheckPermissions
=
sinon
.
spy
();
...
...
@@ -76,6 +78,7 @@ describe("NotificationsIOS", () => {
localNotification
:
nativeLocalNotification
,
cancelLocalNotification
:
nativeCancelLocalNotification
,
cancelAllLocalNotifications
:
nativeCancelAllLocalNotifications
,
getBadgesCount
:
nativeGetBadgesCount
,
setBadgesCount
:
nativeSetBadgesCount
,
isRegisteredForRemoteNotifications
:
nativeIsRegisteredForRemoteNotifications
,
checkPermissions
:
nativeCheckPermissions
,
...
...
@@ -239,6 +242,15 @@ describe("NotificationsIOS", () => {
});
});
describe
(
"
get badges count
"
,
()
=>
{
it
(
"
should call native getBadgesCount
"
,
()
=>
{
const
callback
=
(
count
)
=>
console
.
log
(
count
);
NotificationsIOS
.
getBadgesCount
(
callback
);
expect
(
nativeGetBadgesCount
).
to
.
have
.
been
.
calledWith
(
callback
);
});
});
describe
(
"
set badges count
"
,
()
=>
{
it
(
"
should call native setBadgesCount
"
,
()
=>
{
NotificationsIOS
.
setBadgesCount
(
44
);
...
...
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