Commit 31db8268 authored by Simon MacDonald's avatar Simon MacDonald
Browse files

Send registration event on iOS

parent 4208fa91
Loading
Loading
Loading
Loading
+1 −1
Changes for src/ios/PushPlugin.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@
@property (nonatomic, strong) NSDictionary *notificationMessage;
@property BOOL                          isInline;

- (void)register:(CDVInvokedUrlCommand*)command;
- (void)init:(CDVInvokedUrlCommand*)command;

- (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
+10 −2
Changes for src/ios/PushPlugin.m: 10 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -43,8 +43,9 @@
    [self successWithMessage:@"unregistered"];
}

- (void)register:(CDVInvokedUrlCommand*)command;
- (void)init:(CDVInvokedUrlCommand*)command;
{
    NSLog(@"Push Plugin register called");
	self.callbackId = command.callbackId;

    NSMutableDictionary* options = [command.arguments objectAtIndex:0];
@@ -143,6 +144,7 @@
*/

- (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"Push Plugin register success: %@", deviceToken);

    NSMutableDictionary *results = [NSMutableDictionary dictionary];
    NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
@@ -187,12 +189,18 @@
        [results setValue:dev.model forKey:@"deviceModel"];
        [results setValue:dev.systemVersion forKey:@"deviceSystemVersion"];

		[self successWithMessage:[NSString stringWithFormat:@"%@", token]];
        // Send result to trigger 'registration' event but keep callback
        NSMutableDictionary* message = [NSMutableDictionary dictionaryWithCapacity:1];
        [message setObject:token forKey:@"registrationId"];
        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:message];
        [pluginResult setKeepCallbackAsBool:YES];
        [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
    #endif
}

- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    NSLog(@"Push Plugin register failed");
	[self failWithMessage:@"" withError:error];
}