Commit 9856f121 authored by Omri Bruchim's avatar Omri Bruchim

Add setBadgesCount function (for iOS)

parent e4cd4b91
......@@ -612,6 +612,16 @@ 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)
Set to specific number:
```javascript
NotificationsIOS.setBadgesCount(2);
```
Clear badges icon:
```javascript
NotificationsIOS.setBadgesCount(0);
```
## License
The MIT License.
......
......@@ -476,6 +476,11 @@ RCT_EXPORT_METHOD(registerPushKit)
[RNNotifications registerPushKit];
}
RCT_EXPORT_METHOD(setBadgesCount:(int)count)
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:count];
}
RCT_EXPORT_METHOD(backgroundTimeRemaining:(RCTResponseSenderBlock)callback)
{
NSTimeInterval remainingTime = [UIApplication sharedApplication].backgroundTimeRemaining;
......
......@@ -156,6 +156,10 @@ export default class NotificationsIOS {
_actionHandlers.clear();
}
static setBadgesCount(count: number) {
NativeRNNotifications.setBadgesCount(count);
}
static registerPushKit() {
NativeRNNotifications.registerPushKit();
}
......
......@@ -27,7 +27,9 @@ describe("NotificationsIOS", () => {
nativeConsumeBackgroundQueue,
nativeLocalNotification,
nativeCancelLocalNotification,
nativeCancelAllLocalNotifications;
nativeCancelAllLocalNotifications,
nativeSetBadgesCount;
let NotificationsIOS, NotificationAction, NotificationCategory;
let someHandler = () => {};
let constantGuid = "some-random-uuid";
......@@ -46,6 +48,7 @@ describe("NotificationsIOS", () => {
nativeLocalNotification = sinon.spy();
nativeCancelLocalNotification = sinon.spy();
nativeCancelAllLocalNotifications = sinon.spy();
nativeSetBadgesCount = sinon.spy();
let libUnderTest = proxyquire("../index.ios", {
"uuid": {
......@@ -61,7 +64,8 @@ describe("NotificationsIOS", () => {
consumeBackgroundQueue: nativeConsumeBackgroundQueue,
localNotification: nativeLocalNotification,
cancelLocalNotification: nativeCancelLocalNotification,
cancelAllLocalNotifications: nativeCancelAllLocalNotifications
cancelAllLocalNotifications: nativeCancelAllLocalNotifications,
setBadgesCount: nativeSetBadgesCount
}
},
NativeAppEventEmitter: {
......@@ -208,6 +212,15 @@ describe("NotificationsIOS", () => {
expect(nativeAppRemoveEventListener).to.have.been.calledOnce;
});
});
describe("set badges count", () => {
it("should call native setBadgesCount", () => {
NotificationsIOS.setBadgesCount(44);
expect(nativeSetBadgesCount).to.have.been.calledWith(44);
});
});
});
describe("register push kit for background notifications", function () {
......
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