Commit 3c170df7 authored by Yedidya Kennard's avatar Yedidya Kennard Committed by GitHub

Merge pull request #186 from vehikl/feature/get-badge-count

Added method for getting the current iOS badge count
parents ade806e5 2aaaad99
......@@ -545,6 +545,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];
......
......@@ -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
......
......@@ -160,6 +160,10 @@ export default class NotificationsIOS {
_actionHandlers.clear();
}
static getBadgesCount(callback: Function) {
NativeRNNotifications.getBadgesCount(callback);
}
static setBadgesCount(count: number) {
NativeRNNotifications.setBadgesCount(count);
}
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment