Skip to content

Commit c454ad0

Browse files
committed
2 parents dcd9040 + 92c2eb1 commit c454ad0

5 files changed

Lines changed: 39 additions & 7 deletions

File tree

src/android/ParsePushPlugin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class ParsePushPlugin extends CordovaPlugin {
2727
private static final String ACTION_SUBSCRIBE = "subscribe";
2828
private static final String ACTION_UNSUBSCRIBE = "unsubscribe";
2929
private static final String ACTION_REGISTER_CALLBACK = "registerCallback";
30+
private static final String ACTION_INITIALIZE = "initialize";
3031

3132
private static CallbackContext gEventCallback = null;
3233
private static Queue<PluginResult> pnQueue = new LinkedList();
@@ -68,6 +69,10 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
6869
this.unsubscribe(args.getString(0), callbackContext);
6970
return true;
7071
}
72+
if (action.equals(ACTION_INITIALIZE)) {
73+
this.doInitialization(callbackContext);
74+
return true;
75+
}
7176
return false;
7277
}
7378

@@ -113,6 +118,10 @@ private void unsubscribe(final String channel, final CallbackContext callbackCon
113118
callbackContext.success();
114119
}
115120

121+
private void doInitialization(final CallbackContext callbackContext) {
122+
callbackContext.success();
123+
}
124+
116125
/*
117126
* keep reusing the saved callback context to call the javascript PN handler
118127
*/

src/ios/AppDelegate+parsepush.m

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ - (BOOL)swizzled_application:(UIApplication*)application didFinishLaunchingWithO
9090
//
9191
ParsePushPlugin* pluginInstance = [self getParsePluginInstance];
9292

93-
NSString *appId = [pluginInstance getConfigForKey:@"ParseAppId"];
94-
NSString *serverUrl = [pluginInstance getConfigForKey:@"ParseServerUrl"];
93+
NSString *appId = [pluginInstance getConfigForKey:@"ParseAppId"];
94+
NSString *serverUrl = [pluginInstance getConfigForKey:@"ParseServerUrl"];
95+
NSString *shouldInit = [pluginInstance getConfigForKey:@"ParseAutoRegistration"];
9596

9697
if(!appId.length){
9798
NSException* invalidSettingException = [NSException
@@ -124,11 +125,12 @@ - (BOOL)swizzled_application:(UIApplication*)application didFinishLaunchingWithO
124125
}]];
125126
}
126127

127-
128-
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
129-
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
130-
[application registerUserNotificationSettings:settings];
131-
[application registerForRemoteNotifications];
128+
if (!shouldInit.length || [shouldInit isEqualToString:@"true"]){
129+
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
130+
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
131+
[application registerUserNotificationSettings:settings];
132+
[application registerForRemoteNotifications];
133+
}
132134
}
133135

134136
return isOk;

src/ios/ParsePushPlugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// methods exposed to JS
1111
- (void)registerCallback: (CDVInvokedUrlCommand*)command;
1212

13+
- (void)initialize: (CDVInvokedUrlCommand *)command;
1314
- (void)getInstallationId: (CDVInvokedUrlCommand*)command;
1415
- (void)getInstallationObjectId: (CDVInvokedUrlCommand*)command;
1516

src/ios/ParsePushPlugin.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ - (void)registerCallback: (CDVInvokedUrlCommand*)command
3030
}
3131
}
3232

33+
- (void)initialize:(CDVInvokedUrlCommand *)command
34+
{
35+
CDVPluginResult* pluginResult = nil;
36+
37+
NSString *shouldInit = [self getConfigForKey:@"ParseAutoRegistration"];
38+
if ([shouldInit isEqualToString:@"false"]){
39+
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
40+
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
41+
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
42+
[[UIApplication sharedApplication] registerForRemoteNotifications];
43+
}
44+
45+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
46+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
47+
}
48+
3349
- (void)getInstallationId:(CDVInvokedUrlCommand*) command
3450
{
3551
[self.commandDelegate runInBackground:^{

www/parse-push-plugin.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ var ParsePushPlugin = {
6666
unsubscribe: function(channel, successCb, errorCb) {
6767
cordova.exec(successCb, errorCb, serviceName, 'unsubscribe', [ channel ]);
6868
},
69+
70+
initialize: function(successCb, errorCb) {
71+
cordova.exec(successCb, errorCb, serviceName, 'initialize', []);
72+
},
6973
};
7074

7175
//

0 commit comments

Comments
 (0)