Skip to content

Commit

Permalink
Converted the Badge plugin to Cordova for a project and thought other…
Browse files Browse the repository at this point in the history
…s might want it as well.
  • Loading branch information
JStuhr authored and purplecabbage committed May 16, 2012
1 parent 5ae10ee commit 19d2bf5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
24 changes: 24 additions & 0 deletions iOS/Badge/Badge.h
@@ -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
39 changes: 39 additions & 0 deletions iOS/Badge/Badge.js
@@ -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();
}
});
18 changes: 18 additions & 0 deletions iOS/Badge/Badge.m
@@ -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

0 comments on commit 19d2bf5

Please sign in to comment.