diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ed7607..734e284 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Version 0.3.0 + +- **[Feature]** Allow setting userId that applies to crashes, handled errors and push logs. +- **[iOS][Breaking change]** Drop iOS 8 support. If you encounter errors during a build or the plugin installation please ensure your generated Podfile has proper target (i.e. `platform :ios, '9.0'`) +___ + ## Version 0.2.2 - Updated App Center dependencies diff --git a/cordova-plugin-appcenter-analytics/plugin.xml b/cordova-plugin-appcenter-analytics/plugin.xml index d5f3e0d..82697b7 100644 --- a/cordova-plugin-appcenter-analytics/plugin.xml +++ b/cordova-plugin-appcenter-analytics/plugin.xml @@ -60,6 +60,6 @@ - + diff --git a/cordova-plugin-appcenter-crashes/plugin.xml b/cordova-plugin-appcenter-crashes/plugin.xml index 5e0f7c1..6e35b7c 100644 --- a/cordova-plugin-appcenter-crashes/plugin.xml +++ b/cordova-plugin-appcenter-crashes/plugin.xml @@ -69,6 +69,6 @@ - + diff --git a/cordova-plugin-appcenter-push/plugin.xml b/cordova-plugin-appcenter-push/plugin.xml index b303ee7..4d41e4a 100644 --- a/cordova-plugin-appcenter-push/plugin.xml +++ b/cordova-plugin-appcenter-push/plugin.xml @@ -85,6 +85,6 @@ - + diff --git a/cordova-plugin-appcenter-shared/plugin.xml b/cordova-plugin-appcenter-shared/plugin.xml index 282474c..b652e34 100644 --- a/cordova-plugin-appcenter-shared/plugin.xml +++ b/cordova-plugin-appcenter-shared/plugin.xml @@ -40,7 +40,7 @@ value="com.microsoft.azure.mobile.cordova.AppCenterSharedPlugin"/> - + @@ -55,6 +55,6 @@ - + diff --git a/cordova-plugin-appcenter-shared/src/android/AppCenterShared.java b/cordova-plugin-appcenter-shared/src/android/AppCenterShared.java index 6c41499..367e2ff 100644 --- a/cordova-plugin-appcenter-shared/src/android/AppCenterShared.java +++ b/cordova-plugin-appcenter-shared/src/android/AppCenterShared.java @@ -33,4 +33,8 @@ class AppCenterShared { return AppCenterShared.appSecret; } + + private static void setUserId(String userId) { + AppCenter.setUserId(userId); + } } diff --git a/cordova-plugin-appcenter-shared/src/android/AppCenterSharedPlugin.java b/cordova-plugin-appcenter-shared/src/android/AppCenterSharedPlugin.java index 6d5f3bc..76e01a2 100644 --- a/cordova-plugin-appcenter-shared/src/android/AppCenterSharedPlugin.java +++ b/cordova-plugin-appcenter-shared/src/android/AppCenterSharedPlugin.java @@ -1,6 +1,10 @@ package com.microsoft.azure.mobile.cordova; import com.microsoft.appcenter.AppCenter; +import com.microsoft.appcenter.utils.async.AppCenterFuture; +import com.microsoft.appcenter.utils.async.DefaultAppCenterFuture; + +import android.os.Handler; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; @@ -22,6 +26,28 @@ public class AppCenterSharedPlugin extends CordovaPlugin { AppCenterUtils.sendUUIDPluginResultFromFuture(AppCenter.getInstallId(), callbackContext); return true; } + + if (action.equals("setUserId")) { + String userId = args.getString(0); + AppCenterUtils.sendVoidPluginResultFromFuture(setUserId(userId), callbackContext); + return true; + } + return false; } + + private synchronized AppCenterFuture setUserId(final String userId) { + final DefaultAppCenterFuture future = new DefaultAppCenterFuture<>(); + final Handler handler = new Handler(); + + handler.post(new Runnable() { + @Override + public void run() { + AppCenter.setUserId(userId); + future.complete(null); + } + }); + + return future; + } } diff --git a/cordova-plugin-appcenter-shared/src/ios/AppCenterShared.h b/cordova-plugin-appcenter-shared/src/ios/AppCenterShared.h index 60c1b3c..560e8e9 100644 --- a/cordova-plugin-appcenter-shared/src/ios/AppCenterShared.h +++ b/cordova-plugin-appcenter-shared/src/ios/AppCenterShared.h @@ -6,6 +6,8 @@ + (void) setAppSecret: (NSString *)secret; ++ (void) setUserId: (NSString *)userId; + + (NSString *) getAppSecretWithSettings: (NSDictionary*) settings; + (void) configureWithSettings: (NSDictionary* ) settings; diff --git a/cordova-plugin-appcenter-shared/src/ios/AppCenterShared.m b/cordova-plugin-appcenter-shared/src/ios/AppCenterShared.m index 8500e44..fe4f35c 100644 --- a/cordova-plugin-appcenter-shared/src/ios/AppCenterShared.m +++ b/cordova-plugin-appcenter-shared/src/ios/AppCenterShared.m @@ -12,6 +12,11 @@ static MSWrapperSdk * wrapperSdk; [MSAppCenter configureWithAppSecret:secret]; } ++ (void) setUserId: (NSString *)userId +{ + [MSAppCenter setUserId:userId]; +} + + (NSString *) getAppSecretWithSettings: (NSDictionary*) settings { if (appSecret == nil) { diff --git a/cordova-plugin-appcenter-shared/src/ios/AppCenterSharedPlugin.h b/cordova-plugin-appcenter-shared/src/ios/AppCenterSharedPlugin.h index 30d5bb3..ea49293 100644 --- a/cordova-plugin-appcenter-shared/src/ios/AppCenterSharedPlugin.h +++ b/cordova-plugin-appcenter-shared/src/ios/AppCenterSharedPlugin.h @@ -5,5 +5,6 @@ - (void)pluginInitialize; - (void)getInstallId:(CDVInvokedUrlCommand *)command; +- (void)setUserId:(CDVInvokedUrlCommand *)command; @end diff --git a/cordova-plugin-appcenter-shared/src/ios/AppCenterSharedPlugin.m b/cordova-plugin-appcenter-shared/src/ios/AppCenterSharedPlugin.m index 81467a6..4f7efb3 100644 --- a/cordova-plugin-appcenter-shared/src/ios/AppCenterSharedPlugin.m +++ b/cordova-plugin-appcenter-shared/src/ios/AppCenterSharedPlugin.m @@ -20,4 +20,14 @@ [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; } +- (void)setUserId:(CDVInvokedUrlCommand *)command +{ + NSString* userId = [command argumentAtIndex:0 withDefault:nil andClass:[NSString class]]; + [MSAppCenter setUserId:userId]; + + CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + [self.commandDelegate sendPluginResult:result + callbackId:command.callbackId]; +} + @end diff --git a/cordova-plugin-appcenter-shared/www/AppCenter.js b/cordova-plugin-appcenter-shared/www/AppCenter.js index 98a212a..81d1656 100644 --- a/cordova-plugin-appcenter-shared/www/AppCenter.js +++ b/cordova-plugin-appcenter-shared/www/AppCenter.js @@ -3,6 +3,10 @@ var exec = require('cordova/exec'); var AppCenter = { getInstallId: function (success, error) { exec(success, error, "AppCenterShared", "getInstallId", []); + }, + + setUserId: function (userId, success, error) { + exec(success, error, "AppCenterShared", "setUserId", [userId]); } }; diff --git a/demoapp/config.xml b/demoapp/config.xml index 0b43671..3188cda 100644 --- a/demoapp/config.xml +++ b/demoapp/config.xml @@ -24,6 +24,7 @@ + diff --git a/demoapp/www/index.html b/demoapp/www/index.html index 4bfcdec..80bf282 100644 --- a/demoapp/www/index.html +++ b/demoapp/www/index.html @@ -117,6 +117,8 @@ Log level: 2 +

User ID:

+
diff --git a/demoapp/www/js/apis.js b/demoapp/www/js/apis.js index d5efa41..a9aa187 100644 --- a/demoapp/www/js/apis.js +++ b/demoapp/www/js/apis.js @@ -1,3 +1,14 @@ +var USER_ID_KEY = "userid"; +var userIdProvider = { + put: function (value) { + localStorage.setItem(USER_ID_KEY, value); + }, + + get: function () { + return localStorage.getItem(USER_ID_KEY); + } +} + $(document).bind('pageinit', function () { //The code below wouldn't work for cordova yet. @@ -14,9 +25,23 @@ $(document).bind('pageinit', function () { $("#lbl_log_level").html("Log level: " + logLevel); } + var updateUserId = function() { + var userId = $("#user_id_input").val(); + userIdProvider.put(userId); + AppCenter.setUserId(userId); + } + $("#apis_link").off('click').on('click', function (event, ui) { + var userId = userIdProvider.get(); + $("#user_id_input").val(userId); AppCenter.getInstallId(function (installId) { $("#install_id").html("Install ID: " + installId); }); }); + + $("#user_id_input") + .off("change") + .off("input") + .on("change", updateUserId) + .on("input", updateUserId); });