forked from purplecabbage/phonegap-plugins
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted the Badge plugin to Cordova for a project and thought other…
…s might want it as well.
- Loading branch information
1 parent
5ae10ee
commit 19d2bf5
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Badge.h | ||
// | ||
// Created by Simon Madine on 29/04/2010. | ||
// Copyright 2010 The Angry Robot Zombie Factory. | ||
// MIT licensed | ||
// | ||
// Converted to Cordova by Joseph Stuhr. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#ifdef CORDOVA_FRAMEWORK | ||
#import <Cordova/CDVPlugin.h> | ||
#else | ||
#import "CDVPlugin.h" | ||
#endif | ||
|
||
@interface Badge : CDVPlugin { | ||
} | ||
|
||
- (void)setBadge:(NSMutableArray*)badgeNumber withDict:(NSMutableDictionary*)options; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* This code is adapted from the work of Michael Nachbaur | ||
* by Simon Madine of The Angry Robot Zombie Factory | ||
* 2010-05-04 | ||
* MIT licensed | ||
* | ||
* Converted to Cordova by Joseph Stuhr. | ||
*/ | ||
|
||
/** | ||
* This class exposes the iPhone 'icon badge' functionality to JavaScript | ||
* to add a number (with a red background) to each icon | ||
* @constructor | ||
*/ | ||
function Badge() { | ||
} | ||
|
||
/** | ||
* Positive integer sets the badge, 0 or negative clears it | ||
*/ | ||
Badge.prototype.set = function(options) { | ||
Cordova.exec("Badge.setBadge", options); | ||
}; | ||
|
||
/** | ||
* Shorthand to set the badge to 0 | ||
*/ | ||
Badge.prototype.clear = function() { | ||
Cordova.exec("Badge.setBadge", 0); | ||
}; | ||
|
||
Cordova.addConstructor(function() { | ||
if(!window.plugins) { | ||
window.plugins = {}; | ||
} | ||
if(!window.plugins.badge) { | ||
window.plugins.badge = new Badge(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Badge.m | ||
// | ||
// Created by Simon Madine on 29/04/2010. | ||
// Copyright 2010 The Angry Robot Zombie Factory. | ||
// MIT licensed | ||
// | ||
// Converted to Cordova by Joseph Stuhr. | ||
// | ||
|
||
#import "Badge.h" | ||
|
||
|
||
@implementation Badge | ||
- (void)setBadge:(NSMutableArray*)badgeNumber withDict:(NSMutableDictionary*)options { | ||
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:[[ badgeNumber objectAtIndex:0] intValue]]; | ||
} | ||
@end |