Skip to content

Commit

Permalink
Merge pull request #71 from thomashilzendegen/master
Browse files Browse the repository at this point in the history
cordova-ios 4 compatibility and missing parameter in watch method added
  • Loading branch information
apla committed Jan 6, 2016
2 parents 4cb7247 + fd0c652 commit 0ba3293
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/ios/AppPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ - (void)pluginInitialize
- (void)defaultsChanged:(NSNotification *)notification {

NSString * jsCallBack = [NSString stringWithFormat:@"cordova.fireDocumentEvent('preferencesChanged');"];

#ifdef __CORDOVA_4_0_0
[self.webViewEngine evaluateJavaScript:jsCallBack completionHandler:nil];
#else
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
#endif
}


Expand All @@ -38,7 +43,7 @@ - (void)watch:(CDVInvokedUrlCommand*)command
}

if (watchChanges) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(defaultsChanged) name:NSUserDefaultsDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(defaultsChanged:) name:NSUserDefaultsDidChangeNotification object:nil];
} else {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Expand Down
7 changes: 5 additions & 2 deletions www/apppreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,14 @@ successCallback, errorCallback
* ```
*/
AppPreferences.prototype.watch = platform.watch || function (
successCallback, errorCallback
successCallback, errorCallback, subscribe
) {
if (typeof subscribe === "undefined") {
subscribe = true;
}

var nativeExec = function (resolve, reject) {
return platform.nativeExec (resolve, reject, "AppPreferences", "watch", []);
return platform.nativeExec (resolve, reject, "AppPreferences", "watch", [subscribe]);
}

nativeExec (successCallback, errorCallback);
Expand Down

0 comments on commit 0ba3293

Please sign in to comment.