Commit 4a81b72a by Sebastián Katzer

Update example

parent 6618cb2d
...@@ -69,15 +69,21 @@ ...@@ -69,15 +69,21 @@
*/ */
- (void) add:(CDVInvokedUrlCommand*)command - (void) add:(CDVInvokedUrlCommand*)command
{ {
NSArray* notifications = command.arguments;
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
for (NSDictionary* options in command.arguments) { for (NSMutableDictionary* options in notifications) {
UILocalNotification* notification; UILocalNotification* notification;
notification = [[UILocalNotification alloc] notification = [[UILocalNotification alloc]
initWithOptions:options]; initWithOptions:options];
[self scheduleLocalNotification:notification]; [self scheduleLocalNotification:[notification copy]];
[self fireEvent:@"add" localNotification:notification]; [self fireEvent:@"add" localNotification:notification];
if (notifications.count > 1) {
[NSThread sleepForTimeInterval:0.01];
}
} }
[self execCallback:command]; [self execCallback:command];
...@@ -267,13 +273,6 @@ ...@@ -267,13 +273,6 @@
{ {
[self cancelForerunnerLocalNotification:notification]; [self cancelForerunnerLocalNotification:notification];
NSString* state = self.applicationState;
if ([state isEqualToString:@"background"]) {
[[UIApplication sharedApplication]
presentLocalNotificationNow:notification];
}
[[UIApplication sharedApplication] [[UIApplication sharedApplication]
scheduleLocalNotification:notification]; scheduleLocalNotification:notification];
} }
......
...@@ -35,5 +35,7 @@ ...@@ -35,5 +35,7 @@
// Encode the user info dict to JSON // Encode the user info dict to JSON
- (NSString*) encodeToJSON; - (NSString*) encodeToJSON;
// If it's a repeating notification
- (BOOL) isRepeating;
@end @end
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
- (BOOL) autoCancel - (BOOL) autoCancel
{ {
if (IsAtLeastiOSVersion(@"8.0")){ if (IsAtLeastiOSVersion(@"8.0")){
return self.repeatInterval == NSCalendarUnitEra; return ![self isRepeating];
} else { } else {
return [[dict objectForKey:@"autoCancel"] boolValue]; return [[dict objectForKey:@"autoCancel"] boolValue];
} }
...@@ -201,6 +201,9 @@ ...@@ -201,6 +201,9 @@
return NSCalendarUnitEra; return NSCalendarUnitEra;
} }
#pragma mark -
#pragma mark Methods
/** /**
* The notification's user info dict. * The notification's user info dict.
*/ */
...@@ -231,6 +234,16 @@ ...@@ -231,6 +234,16 @@
withString:@""]; withString:@""];
} }
/**
* If it's a repeating notification.
*/
- (BOOL) isRepeating
{
NSCalendarUnit interval = self.repeatInterval;
return !(interval == NSCalendarUnitEra || interval == 0);
}
#pragma mark - #pragma mark -
#pragma mark Helpers #pragma mark Helpers
......
...@@ -33,5 +33,7 @@ ...@@ -33,5 +33,7 @@
- (BOOL) wasInThePast; - (BOOL) wasInThePast;
// If the notification was already triggered // If the notification was already triggered
- (BOOL) wasTriggered; - (BOOL) wasTriggered;
// If it's a repeating notification
- (BOOL) isRepeating;
@end @end
...@@ -61,6 +61,9 @@ static char optionsKey; ...@@ -61,6 +61,9 @@ static char optionsKey;
self.soundName = options.soundName; self.soundName = options.soundName;
} }
#pragma mark -
#pragma mark Methods
/** /**
* The options provided by the plug-in. * The options provided by the plug-in.
*/ */
...@@ -128,7 +131,7 @@ static char optionsKey; ...@@ -128,7 +131,7 @@ static char optionsKey;
int timespan = [now timeIntervalSinceDate:fireDate]; int timespan = [now timeIntervalSinceDate:fireDate];
if (self.repeatInterval != NSCalendarUnitEra) { if ([self isRepeating]) {
timespan = timespan % [self repeatIntervalInSeconds]; timespan = timespan % [self repeatIntervalInSeconds];
} }
...@@ -156,4 +159,12 @@ static char optionsKey; ...@@ -156,4 +159,12 @@ static char optionsKey;
return isLaterThanOrEqualTo; return isLaterThanOrEqualTo;
} }
/**
* If it's a repeating notification.
*/
- (BOOL) isRepeating
{
return [self.options isRepeating];
}
@end @end
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
<script type="text/javascript" src="js/index.js"></script> <script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var counter = 1, id = 12; var counter = 0, id = 1;
var callback = function () { var callback = function () {
alert('finished or canceled'); alert('finished or canceled');
...@@ -138,15 +138,15 @@ ...@@ -138,15 +138,15 @@
scheduleMultiple = function () { scheduleMultiple = function () {
plugin.notification.local.add([{ plugin.notification.local.add([{
id: id, id: id,
message: 'Test Message ' + (++counter), message: 'Multi Message ' + (++counter),
json: { test: id } json: { test: id }
},{ },{
id: id+1, id: id+1,
message: 'Test Message ' + (++counter), message: 'Multi Message ' + (++counter),
json: { test: id+1 } json: { test: id+1 }
},{ },{
id: id+2, id: id+2,
message: 'Test Message ' + (++counter), message: 'Multi Message ' + (++counter),
json: { test: id+2 } json: { test: id+2 }
}]); }]);
}; };
...@@ -214,14 +214,14 @@ ...@@ -214,14 +214,14 @@
setDefaultTitle = function () { setDefaultTitle = function () {
plugin.notification.local.setDefaults({ plugin.notification.local.setDefaults({
title: 'Default Title', title: 'New Default Title',
}); });
}; };
</script> </script>
<!-- callbacks --> <!-- callbacks -->
<script type="text/javascript"> <script type="text/javascript">
document.addEventListener('sdeviceready', function () { document.addEventListener('deviceready', function () {
plugin.notification.local.onadd = function (id, state, json) { plugin.notification.local.onadd = function (id, state, json) {
alert('on add\n' + Array.apply(null, arguments).join("\n")); alert('on add\n' + Array.apply(null, arguments).join("\n"));
}; };
......
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
<script type="text/javascript" src="js/index.js"></script> <script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var counter = 1, id = 12; var counter = 0, id = 1;
var callback = function () { var callback = function () {
alert('finished or canceled'); alert('finished or canceled');
...@@ -138,15 +138,15 @@ ...@@ -138,15 +138,15 @@
scheduleMultiple = function () { scheduleMultiple = function () {
plugin.notification.local.add([{ plugin.notification.local.add([{
id: id, id: id,
message: 'Test Message ' + (++counter), message: 'Multi Message ' + (++counter),
json: { test: id } json: { test: id }
},{ },{
id: id+1, id: id+1,
message: 'Test Message ' + (++counter), message: 'Multi Message ' + (++counter),
json: { test: id+1 } json: { test: id+1 }
},{ },{
id: id+2, id: id+2,
message: 'Test Message ' + (++counter), message: 'Multi Message ' + (++counter),
json: { test: id+2 } json: { test: id+2 }
}]); }]);
}; };
...@@ -214,14 +214,14 @@ ...@@ -214,14 +214,14 @@
setDefaultTitle = function () { setDefaultTitle = function () {
plugin.notification.local.setDefaults({ plugin.notification.local.setDefaults({
title: 'Default Title', title: 'New Default Title',
}); });
}; };
</script> </script>
<!-- callbacks --> <!-- callbacks -->
<script type="text/javascript"> <script type="text/javascript">
document.addEventListener('sdeviceready', function () { document.addEventListener('deviceready', function () {
plugin.notification.local.onadd = function (id, state, json) { plugin.notification.local.onadd = function (id, state, json) {
alert('on add\n' + Array.apply(null, arguments).join("\n")); alert('on add\n' + Array.apply(null, arguments).join("\n"));
}; };
......
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