Commit 3afc1f04 by Sebastián Katzer

Click event on iOS wasn't fired if app was not running (solves #87).

parent 5a098fb4
...@@ -64,6 +64,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/413). ...@@ -64,6 +64,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/413).
- [feature:] New interface `getScheduledIds` to retrieve a list with all currently pending notifications. - [feature:] New interface `getScheduledIds` to retrieve a list with all currently pending notifications.
- [enhancement:] Support for bigview style notifications for Android devices. - [enhancement:] Support for bigview style notifications for Android devices.
- [bugfix:] Sound didnt play properly on iOS/Android. - [bugfix:] Sound didnt play properly on iOS/Android.
- [bugfix:] click event on iOS wasn't fired if app was not running.
#### Version 0.7.2 (09.02.2014) #### Version 0.7.2 (09.02.2014)
- [enhancement:] Avoid blocking the main thread (on Android) **(dpogue)**. - [enhancement:] Avoid blocking the main thread (on Android) **(dpogue)**.
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
@interface APPLocalNotification : CDVPlugin @interface APPLocalNotification : CDVPlugin
// Executes all queued events
- (void) deviceready:(CDVInvokedUrlCommand*)command;
// Schedules a new local notification // Schedules a new local notification
- (void) add:(CDVInvokedUrlCommand*)command; - (void) add:(CDVInvokedUrlCommand*)command;
// Cancels a given local notification // Cancels a given local notification
......
...@@ -54,8 +54,33 @@ ...@@ -54,8 +54,33 @@
@end @end
@interface APPLocalNotification ()
// All events will be queued until deviceready has been fired
@property (readwrite, assign) BOOL deviceready;
// Event queue
@property (readonly, nonatomic, retain) NSMutableArray* eventQueue;
@end
@implementation APPLocalNotification @implementation APPLocalNotification
@synthesize deviceready, eventQueue;
/**
* Executes all queued events.
*/
- (void) deviceready:(CDVInvokedUrlCommand*)command
{
deviceready = YES;
for (NSString* js in eventQueue) {
[self.commandDelegate evalJs:js];
}
[eventQueue removeAllObjects];
}
/** /**
* Schedules a new local notification. * Schedules a new local notification.
* *
...@@ -109,8 +134,7 @@ ...@@ -109,8 +134,7 @@
NSArray* notifications = [[UIApplication sharedApplication] NSArray* notifications = [[UIApplication sharedApplication]
scheduledLocalNotifications]; scheduledLocalNotifications];
for (UILocalNotification* notification in notifications) for (UILocalNotification* notification in notifications) {
{
[self cancelNotification:notification fireEvent:YES]; [self cancelNotification:notification fireEvent:YES];
} }
...@@ -214,8 +238,7 @@ ...@@ -214,8 +238,7 @@
[[UIApplication sharedApplication] [[UIApplication sharedApplication]
cancelLocalNotification:notification]; cancelLocalNotification:notification];
if (fireEvent) if (fireEvent) {
{
[self fireEvent:@"cancel" id:id json:json]; [self fireEvent:@"cancel" id:id json:json];
} }
} }
...@@ -339,13 +362,10 @@ ...@@ -339,13 +362,10 @@
if (![self stringIsNullOrEmpty:msg]) if (![self stringIsNullOrEmpty:msg])
{ {
if (![self stringIsNullOrEmpty:title]) if (![self stringIsNullOrEmpty:title]) {
{
notification.alertBody = [NSString stringWithFormat: notification.alertBody = [NSString stringWithFormat:
@"%@\n%@", title, msg]; @"%@\n%@", title, msg];
} } else {
else
{
notification.alertBody = msg; notification.alertBody = msg;
} }
} }
...@@ -354,9 +374,7 @@ ...@@ -354,9 +374,7 @@
{ {
if ([sound isEqualToString:@""]) { if ([sound isEqualToString:@""]) {
notification.soundName = UILocalNotificationDefaultSoundName; notification.soundName = UILocalNotificationDefaultSoundName;
} } else {
else
{
notification.soundName = sound; notification.soundName = sound;
} }
} }
...@@ -382,8 +400,7 @@ ...@@ -382,8 +400,7 @@
NSTimeInterval fireDateDistance = [now timeIntervalSinceDate:fireDate]; NSTimeInterval fireDateDistance = [now timeIntervalSinceDate:fireDate];
NSString* event = (fireDateDistance < 1) ? @"trigger" : @"click"; NSString* event = (fireDateDistance < 1) ? @"trigger" : @"click";
if (autoCancel && [event isEqualToString:@"click"]) if (autoCancel && [event isEqualToString:@"click"]) {
{
[self cancelNotification:notification fireEvent:YES]; [self cancelNotification:notification fireEvent:YES];
} }
...@@ -400,8 +417,7 @@ ...@@ -400,8 +417,7 @@
UILocalNotification* localNotification = [launchOptions objectForKey: UILocalNotification* localNotification = [launchOptions objectForKey:
UIApplicationLaunchOptionsLocalNotificationKey]; UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) if (localNotification) {
{
[self didReceiveLocalNotification: [self didReceiveLocalNotification:
[NSNotification notificationWithName:CDVLocalNotification [NSNotification notificationWithName:CDVLocalNotification
object:localNotification]]; object:localNotification]];
...@@ -418,6 +434,8 @@ ...@@ -418,6 +434,8 @@
NSNotificationCenter* notificationCenter = [NSNotificationCenter NSNotificationCenter* notificationCenter = [NSNotificationCenter
defaultCenter]; defaultCenter];
eventQueue = [[NSMutableArray alloc] init];
[notificationCenter addObserver:self [notificationCenter addObserver:self
selector:@selector(didReceiveLocalNotification:) selector:@selector(didReceiveLocalNotification:)
name:CDVLocalNotification name:CDVLocalNotification
...@@ -425,7 +443,7 @@ ...@@ -425,7 +443,7 @@
[notificationCenter addObserver:self [notificationCenter addObserver:self
selector:@selector(didFinishLaunchingWithOptions:) selector:@selector(didFinishLaunchingWithOptions:)
name:CDVLocalNotification name:UIApplicationDidFinishLaunchingNotification
object:nil]; object:nil];
} }
...@@ -446,13 +464,11 @@ ...@@ -446,13 +464,11 @@
*/ */
- (BOOL) stringIsNullOrEmpty:(NSString*)str - (BOOL) stringIsNullOrEmpty:(NSString*)str
{ {
if (str == (NSString*)[NSNull null]) if (str == (NSString*)[NSNull null]) {
{
return YES; return YES;
} }
if ([str isEqualToString:@""]) if ([str isEqualToString:@""]) {
{
return YES; return YES;
} }
...@@ -523,7 +539,11 @@ ...@@ -523,7 +539,11 @@
@"setTimeout('plugin.notification.local.on%@(%@)',0)", @"setTimeout('plugin.notification.local.on%@(%@)',0)",
event, params]; event, params];
[self.commandDelegate evalJs:js]; if (deviceready) {
[self.commandDelegate evalJs:js];
} else {
[self.eventQueue addObject:js];
}
} }
@end @end
...@@ -212,4 +212,8 @@ channel.onCordovaReady.subscribe( function () { ...@@ -212,4 +212,8 @@ channel.onCordovaReady.subscribe( function () {
plugin.applyPlatformSpecificOptions(); plugin.applyPlatformSpecificOptions();
}); });
channel.deviceready.subscribe( function () {
cordova.exec(null, null, 'LocalNotification', 'deviceready', []);
});
module.exports = plugin; module.exports = plugin;
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