Commit 54955460 by Sebastián Katzer

Update IOS to 0.9.0.beta

parent 9c65b6c2
...@@ -596,8 +596,9 @@ ...@@ -596,8 +596,9 @@
withCompletionHandler:(void (^)())completionHandler withCompletionHandler:(void (^)())completionHandler
{ {
UNNotificationRequest* notification = response.notification.request; UNNotificationRequest* notification = response.notification.request;
NSString* action = response.actionIdentifier; NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
NSString* event = action; NSString* action = response.actionIdentifier;
NSString* event = action;
completionHandler(); completionHandler();
...@@ -611,12 +612,17 @@ ...@@ -611,12 +612,17 @@
if (!deviceready && [event isEqualToString:@"click"]) { if (!deviceready && [event isEqualToString:@"click"]) {
_launchDetails = @[notification.options.id, event]; _launchDetails = @[notification.options.id, event];
} }
if (![event isEqualToString:@"clear"]) { if (![event isEqualToString:@"clear"]) {
[self fireEvent:@"clear" notification:notification]; [self fireEvent:@"clear" notification:notification];
} }
if ([response isKindOfClass:UNTextInputNotificationResponse.class]) {
[data setObject:((UNTextInputNotificationResponse*) response).userText
forKey:@"text"];
}
[self fireEvent:event notification:notification]; [self fireEvent:event notification:notification data:data];
} }
#pragma mark - #pragma mark -
...@@ -639,20 +645,6 @@ ...@@ -639,20 +645,6 @@
#pragma mark Helper #pragma mark Helper
/** /**
* Retrieve the state of the application.
*
* @return "background" or "foreground"
*/
- (NSString*) applicationState
{
UIApplicationState state = [_app applicationState];
bool isActive = state == UIApplicationStateActive;
return isActive ? @"foreground" : @"background";
}
/**
* Simply invokes the callback without any parameter. * Simply invokes the callback without any parameter.
*/ */
- (void) execCallback:(CDVInvokedUrlCommand*)command - (void) execCallback:(CDVInvokedUrlCommand*)command
...@@ -673,7 +665,9 @@ ...@@ -673,7 +665,9 @@
*/ */
- (void) fireEvent:(NSString*)event - (void) fireEvent:(NSString*)event
{ {
[self fireEvent:event notification:NULL]; NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
[self fireEvent:event notification:NULL data:data];
} }
/** /**
...@@ -685,15 +679,48 @@ ...@@ -685,15 +679,48 @@
* @return [ Void ] * @return [ Void ]
*/ */
- (void) fireEvent:(NSString*)event - (void) fireEvent:(NSString*)event
notification:(UNNotificationRequest*)notitification
{
NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
[self fireEvent:event notification:notitification data:data];
}
/**
* Fire event for about a local notification.
*
* @param [ NSString* ] event The name of the event to fire.
* @param [ APPNotificationRequest* ] notification The local notification.
* @param [ NSMutableDictionary* ] data Event object with additional data.
*
* @return [ Void ]
*/
- (void) fireEvent:(NSString*)event
notification:(UNNotificationRequest*)request notification:(UNNotificationRequest*)request
data:(NSMutableDictionary*)data
{ {
NSString *js; BOOL isActive = [_app applicationState] == UIApplicationStateActive;
NSString *appState = [self applicationState]; NSString *js, *params, *notiAsJSON, *dataAsJSON;
NSString *params = [NSString stringWithFormat:@"\"%@\"", appState]; NSData* dataAsData;
[data setObject:event forKey:@"event"];
[data setObject:@(isActive) forKey:@"foreground"];
if (request) { if (request) {
NSString *args = [request encodeToJSON]; notiAsJSON = [request encodeToJSON];
params = [NSString stringWithFormat:@"%@,'%@'", args, appState]; [data setObject:request.options.id forKey:@"notification"];
}
dataAsData =
[NSJSONSerialization dataWithJSONObject:data options:0 error:NULL];
dataAsJSON =
[[NSString alloc] initWithData:dataAsData encoding:NSUTF8StringEncoding];
if (request) {
params = [NSString stringWithFormat:@"%@,%@", notiAsJSON, dataAsJSON];
} else {
params = [NSString stringWithFormat:@"%@", dataAsJSON];
} }
js = [NSString stringWithFormat: js = [NSString stringWithFormat:
......
...@@ -61,9 +61,9 @@ ...@@ -61,9 +61,9 @@
* *
* @return [ NSString* ] * @return [ NSString* ]
*/ */
- (NSString*) type - (NSString*) triggerType
{ {
NSString* type = [dict objectForKey:@"type"]; NSString* type = [dict objectForKey:@"trigger"];
return type.length ? type : @"normal"; return type.length ? type : @"normal";
} }
...@@ -276,12 +276,12 @@ ...@@ -276,12 +276,12 @@
*/ */
- (UNNotificationTrigger*) trigger - (UNNotificationTrigger*) trigger
{ {
NSString* type = [self type]; NSString* type = [self triggerType];
if ([type isEqualToString:@"location"]) if ([type isEqualToString:@"location"])
return [self triggerWithRegion]; return [self triggerWithRegion];
if (![type isEqualToString:@"normal"]) if (![type isEqualToString:@"date"])
NSLog(@"Unknown type: %@", type); NSLog(@"Unknown type: %@", type);
if ([self isRepeating]) if ([self isRepeating])
......
...@@ -22,16 +22,16 @@ var exec = require('cordova/exec'), ...@@ -22,16 +22,16 @@ var exec = require('cordova/exec'),
// Default values // Default values
exports._defaults = { exports._defaults = {
id: 0, id: 0,
type: 'normal',
text: '', text: '',
title: '', title: '',
sound: 'res://platform_default', sound: 'res://platform_default',
trigger: 'date',
badge: undefined, badge: undefined,
data: undefined, data: undefined,
every: undefined, every: undefined,
at: undefined, at: undefined,
actions: undefined, actions: undefined,
actionGroupId: undefined actionGroupId: undefined,
}; };
// Listener // Listener
...@@ -55,9 +55,11 @@ exports.applyPlatformSpecificOptions = function () { ...@@ -55,9 +55,11 @@ exports.applyPlatformSpecificOptions = function () {
defaults.color = undefined; defaults.color = undefined;
break; break;
case 'iOS': case 'iOS':
defaults.attachments = undefined; defaults.attachments = undefined;
defaults.region = undefined; defaults.region = undefined;
defaults.radius = undefined; defaults.radius = undefined;
defaults.notifyOnEntry = true;
defaults.notifyOnExit = false;
break; break;
} }
}; };
......
...@@ -325,6 +325,10 @@ var app = { ...@@ -325,6 +325,10 @@ var app = {
console.log('dislike', arguments); console.log('dislike', arguments);
showToast('disliked'); showToast('disliked');
}); });
cordova.plugins.notification.local.on('feedback', function (obj, e) {
console.log('feedback', arguments);
showToast('Feedback: ' + e.text);
});
} }
}; };
......
...@@ -22,16 +22,16 @@ var exec = require('cordova/exec'), ...@@ -22,16 +22,16 @@ var exec = require('cordova/exec'),
// Default values // Default values
exports._defaults = { exports._defaults = {
id: 0, id: 0,
type: 'normal',
text: '', text: '',
title: '', title: '',
sound: 'res://platform_default', sound: 'res://platform_default',
trigger: 'date',
badge: undefined, badge: undefined,
data: undefined, data: undefined,
every: undefined, every: undefined,
at: undefined, at: undefined,
actions: undefined, actions: undefined,
actionGroupId: undefined actionGroupId: undefined,
}; };
// Listener // Listener
...@@ -55,9 +55,11 @@ exports.applyPlatformSpecificOptions = function () { ...@@ -55,9 +55,11 @@ exports.applyPlatformSpecificOptions = function () {
defaults.color = undefined; defaults.color = undefined;
break; break;
case 'iOS': case 'iOS':
defaults.attachments = undefined; defaults.attachments = undefined;
defaults.region = undefined; defaults.region = undefined;
defaults.radius = undefined; defaults.radius = undefined;
defaults.notifyOnEntry = true;
defaults.notifyOnExit = false;
break; break;
} }
}; };
......
...@@ -596,8 +596,9 @@ ...@@ -596,8 +596,9 @@
withCompletionHandler:(void (^)())completionHandler withCompletionHandler:(void (^)())completionHandler
{ {
UNNotificationRequest* notification = response.notification.request; UNNotificationRequest* notification = response.notification.request;
NSString* action = response.actionIdentifier; NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
NSString* event = action; NSString* action = response.actionIdentifier;
NSString* event = action;
completionHandler(); completionHandler();
...@@ -611,12 +612,17 @@ ...@@ -611,12 +612,17 @@
if (!deviceready && [event isEqualToString:@"click"]) { if (!deviceready && [event isEqualToString:@"click"]) {
_launchDetails = @[notification.options.id, event]; _launchDetails = @[notification.options.id, event];
} }
if (![event isEqualToString:@"clear"]) { if (![event isEqualToString:@"clear"]) {
[self fireEvent:@"clear" notification:notification]; [self fireEvent:@"clear" notification:notification];
} }
if ([response isKindOfClass:UNTextInputNotificationResponse.class]) {
[data setObject:((UNTextInputNotificationResponse*) response).userText
forKey:@"text"];
}
[self fireEvent:event notification:notification]; [self fireEvent:event notification:notification data:data];
} }
#pragma mark - #pragma mark -
...@@ -639,20 +645,6 @@ ...@@ -639,20 +645,6 @@
#pragma mark Helper #pragma mark Helper
/** /**
* Retrieve the state of the application.
*
* @return "background" or "foreground"
*/
- (NSString*) applicationState
{
UIApplicationState state = [_app applicationState];
bool isActive = state == UIApplicationStateActive;
return isActive ? @"foreground" : @"background";
}
/**
* Simply invokes the callback without any parameter. * Simply invokes the callback without any parameter.
*/ */
- (void) execCallback:(CDVInvokedUrlCommand*)command - (void) execCallback:(CDVInvokedUrlCommand*)command
...@@ -673,7 +665,9 @@ ...@@ -673,7 +665,9 @@
*/ */
- (void) fireEvent:(NSString*)event - (void) fireEvent:(NSString*)event
{ {
[self fireEvent:event notification:NULL]; NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
[self fireEvent:event notification:NULL data:data];
} }
/** /**
...@@ -685,15 +679,48 @@ ...@@ -685,15 +679,48 @@
* @return [ Void ] * @return [ Void ]
*/ */
- (void) fireEvent:(NSString*)event - (void) fireEvent:(NSString*)event
notification:(UNNotificationRequest*)notitification
{
NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
[self fireEvent:event notification:notitification data:data];
}
/**
* Fire event for about a local notification.
*
* @param [ NSString* ] event The name of the event to fire.
* @param [ APPNotificationRequest* ] notification The local notification.
* @param [ NSMutableDictionary* ] data Event object with additional data.
*
* @return [ Void ]
*/
- (void) fireEvent:(NSString*)event
notification:(UNNotificationRequest*)request notification:(UNNotificationRequest*)request
data:(NSMutableDictionary*)data
{ {
NSString *js; BOOL isActive = [_app applicationState] == UIApplicationStateActive;
NSString *appState = [self applicationState]; NSString *js, *params, *notiAsJSON, *dataAsJSON;
NSString *params = [NSString stringWithFormat:@"\"%@\"", appState]; NSData* dataAsData;
[data setObject:event forKey:@"event"];
[data setObject:@(isActive) forKey:@"foreground"];
if (request) { if (request) {
NSString *args = [request encodeToJSON]; notiAsJSON = [request encodeToJSON];
params = [NSString stringWithFormat:@"%@,'%@'", args, appState]; [data setObject:request.options.id forKey:@"notification"];
}
dataAsData =
[NSJSONSerialization dataWithJSONObject:data options:0 error:NULL];
dataAsJSON =
[[NSString alloc] initWithData:dataAsData encoding:NSUTF8StringEncoding];
if (request) {
params = [NSString stringWithFormat:@"%@,%@", notiAsJSON, dataAsJSON];
} else {
params = [NSString stringWithFormat:@"%@", dataAsJSON];
} }
js = [NSString stringWithFormat: js = [NSString stringWithFormat:
......
...@@ -61,9 +61,9 @@ ...@@ -61,9 +61,9 @@
* *
* @return [ NSString* ] * @return [ NSString* ]
*/ */
- (NSString*) type - (NSString*) triggerType
{ {
NSString* type = [dict objectForKey:@"type"]; NSString* type = [dict objectForKey:@"trigger"];
return type.length ? type : @"normal"; return type.length ? type : @"normal";
} }
...@@ -276,12 +276,12 @@ ...@@ -276,12 +276,12 @@
*/ */
- (UNNotificationTrigger*) trigger - (UNNotificationTrigger*) trigger
{ {
NSString* type = [self type]; NSString* type = [self triggerType];
if ([type isEqualToString:@"location"]) if ([type isEqualToString:@"location"])
return [self triggerWithRegion]; return [self triggerWithRegion];
if (![type isEqualToString:@"normal"]) if (![type isEqualToString:@"date"])
NSLog(@"Unknown type: %@", type); NSLog(@"Unknown type: %@", type);
if ([self isRepeating]) if ([self isRepeating])
......
...@@ -21,16 +21,16 @@ var exec = require('cordova/exec'), ...@@ -21,16 +21,16 @@ var exec = require('cordova/exec'),
// Default values // Default values
exports._defaults = { exports._defaults = {
id: 0, id: 0,
type: 'normal',
text: '', text: '',
title: '', title: '',
sound: 'res://platform_default', sound: 'res://platform_default',
trigger: 'date',
badge: undefined, badge: undefined,
data: undefined, data: undefined,
every: undefined, every: undefined,
at: undefined, at: undefined,
actions: undefined, actions: undefined,
actionGroupId: undefined actionGroupId: undefined,
}; };
// Listener // Listener
...@@ -54,9 +54,11 @@ exports.applyPlatformSpecificOptions = function () { ...@@ -54,9 +54,11 @@ exports.applyPlatformSpecificOptions = function () {
defaults.color = undefined; defaults.color = undefined;
break; break;
case 'iOS': case 'iOS':
defaults.attachments = undefined; defaults.attachments = undefined;
defaults.region = undefined; defaults.region = undefined;
defaults.radius = undefined; defaults.radius = undefined;
defaults.notifyOnEntry = true;
defaults.notifyOnExit = false;
break; break;
} }
}; };
......
...@@ -325,6 +325,10 @@ var app = { ...@@ -325,6 +325,10 @@ var app = {
console.log('dislike', arguments); console.log('dislike', arguments);
showToast('disliked'); showToast('disliked');
}); });
cordova.plugins.notification.local.on('feedback', function (obj, e) {
console.log('feedback', arguments);
showToast('Feedback: ' + e.text);
});
} }
}; };
......
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