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) ...@@ -545,6 +545,12 @@ RCT_EXPORT_METHOD(registerPushKit)
[RNNotifications registerPushKit]; [RNNotifications registerPushKit];
} }
RCT_EXPORT_METHOD(getBadgesCount:(RCTResponseSenderBlock)callback)
{
NSInteger count = [UIApplication sharedApplication].applicationIconBadgeNumber;
callback(@[ [NSNumber numberWithInteger:count] ]);
}
RCT_EXPORT_METHOD(setBadgesCount:(int)count) RCT_EXPORT_METHOD(setBadgesCount:(int)count)
{ {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:count]; [[UIApplication sharedApplication] setApplicationIconBadgeNumber:count];
......
...@@ -260,7 +260,12 @@ The [example app](https://github.com/wix/react-native-notifications/tree/master/ ...@@ -260,7 +260,12 @@ The [example app](https://github.com/wix/react-native-notifications/tree/master/
- `minimal` - Displays up tp 2 actions (minimal UI). - `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: Set to specific number:
```javascript ```javascript
......
...@@ -160,6 +160,10 @@ export default class NotificationsIOS { ...@@ -160,6 +160,10 @@ export default class NotificationsIOS {
_actionHandlers.clear(); _actionHandlers.clear();
} }
static getBadgesCount(callback: Function) {
NativeRNNotifications.getBadgesCount(callback);
}
static setBadgesCount(count: number) { static setBadgesCount(count: number) {
NativeRNNotifications.setBadgesCount(count); NativeRNNotifications.setBadgesCount(count);
} }
......
...@@ -28,6 +28,7 @@ describe("NotificationsIOS", () => { ...@@ -28,6 +28,7 @@ describe("NotificationsIOS", () => {
nativeLocalNotification, nativeLocalNotification,
nativeCancelLocalNotification, nativeCancelLocalNotification,
nativeCancelAllLocalNotifications, nativeCancelAllLocalNotifications,
nativeGetBadgesCount,
nativeSetBadgesCount, nativeSetBadgesCount,
nativeIsRegisteredForRemoteNotifications, nativeIsRegisteredForRemoteNotifications,
nativeCheckPermissions, nativeCheckPermissions,
...@@ -54,6 +55,7 @@ describe("NotificationsIOS", () => { ...@@ -54,6 +55,7 @@ describe("NotificationsIOS", () => {
nativeLocalNotification = sinon.spy(); nativeLocalNotification = sinon.spy();
nativeCancelLocalNotification = sinon.spy(); nativeCancelLocalNotification = sinon.spy();
nativeCancelAllLocalNotifications = sinon.spy(); nativeCancelAllLocalNotifications = sinon.spy();
nativeGetBadgesCount = sinon.spy();
nativeSetBadgesCount = sinon.spy(); nativeSetBadgesCount = sinon.spy();
nativeIsRegisteredForRemoteNotifications = sinon.spy(); nativeIsRegisteredForRemoteNotifications = sinon.spy();
nativeCheckPermissions = sinon.spy(); nativeCheckPermissions = sinon.spy();
...@@ -76,6 +78,7 @@ describe("NotificationsIOS", () => { ...@@ -76,6 +78,7 @@ describe("NotificationsIOS", () => {
localNotification: nativeLocalNotification, localNotification: nativeLocalNotification,
cancelLocalNotification: nativeCancelLocalNotification, cancelLocalNotification: nativeCancelLocalNotification,
cancelAllLocalNotifications: nativeCancelAllLocalNotifications, cancelAllLocalNotifications: nativeCancelAllLocalNotifications,
getBadgesCount: nativeGetBadgesCount,
setBadgesCount: nativeSetBadgesCount, setBadgesCount: nativeSetBadgesCount,
isRegisteredForRemoteNotifications: nativeIsRegisteredForRemoteNotifications, isRegisteredForRemoteNotifications: nativeIsRegisteredForRemoteNotifications,
checkPermissions: nativeCheckPermissions, checkPermissions: nativeCheckPermissions,
...@@ -239,6 +242,15 @@ describe("NotificationsIOS", () => { ...@@ -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", () => { describe("set badges count", () => {
it("should call native setBadgesCount", () => { it("should call native setBadgesCount", () => {
NotificationsIOS.setBadgesCount(44); 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