Skip to content

Commit 8bb43b9

Browse files
committed
Add getApplicationIconBadgeNumber method
1 parent bdbc198 commit 8bb43b9

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ The `count` is an integer indicating what number should show up in the badge. Pa
177177
push.setApplicationIconBadgeNumber(successHandler, errorHandler, count);
178178
```
179179

180+
### push.getApplicationIconBadgeNumber(successHandler, errorHandler) - iOS only
181+
182+
Get the current badge count visible when the app is not running
183+
184+
successHandler gets called with an integer which is the current badge count
185+
186+
#### Example
187+
188+
```javascript
189+
push.getApplicationIconBadgeNumber(successHandler, errorHandler);
190+
```
191+
180192
## PhoneGap Build Support
181193

182194
Including this plugin in a project that is built by PhoneGap Build is as easy as adding:

spec/index.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ describe('phonegap-plugin-push', function() {
3636
expect(typeof push.unregister == 'function').toBe(true);
3737
});
3838

39+
it("should contain a getApplicationIconBadgeNumber function", function() {
40+
var push = PushNotification.init({});
41+
expect(push.getApplicationIconBadgeNumber).toBeDefined();
42+
expect(typeof push.getApplicationIconBadgeNumber == 'function').toBe(true);
43+
});
44+
3945
it("should contain a setApplicationIconBadgeNumber function", function() {
4046
var push = PushNotification.init({});
4147
expect(push.setApplicationIconBadgeNumber).toBeDefined();

src/ios/PushPlugin.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ - (void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command
271271
[self.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId];
272272
}
273273

274+
- (void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command
275+
{
276+
NSInteger badge = [UIApplication sharedApplication].applicationIconBadgeNumber;
277+
278+
CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:(int)badge];
279+
[self.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId];
280+
}
281+
274282
-(void)successWithMessage:(NSString *)message
275283
{
276284
if (self.callbackId != nil)

www/push.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ PushNotification.prototype.setApplicationIconBadgeNumber = function(successCallb
102102
exec(successCallback, errorCallback, "PushNotification", "setApplicationIconBadgeNumber", [{badge: badge}]);
103103
};
104104

105+
/**
106+
* Get the application icon badge
107+
*/
108+
109+
PushNotification.prototype.getApplicationIconBadgeNumber = function(successCallback, errorCallback) {
110+
if (errorCallback == null) { errorCallback = function() {}}
111+
112+
if (typeof errorCallback != "function") {
113+
console.log("PushNotification.getApplicationIconBadgeNumber failure: failure parameter not a function");
114+
return
115+
}
116+
117+
if (typeof successCallback != "function") {
118+
console.log("PushNotification.getApplicationIconBadgeNumber failure: success callback parameter must be a function");
119+
return
120+
}
121+
122+
exec(successCallback, errorCallback, "PushNotification", "getApplicationIconBadgeNumber", []);
123+
};
124+
105125
/**
106126
* Listen for an event.
107127
*

0 commit comments

Comments
 (0)