Implement setUserId for iOS and Android (#65)
* Add setUserId handling for iOS * Implement setUserId calling * Add deployment target to config.xml * Revert unneeded changes * Add Android bindings * Store userId between app restarts * Fix review comments * Update demoapp/www/js/apis.js Co-Authored-By: nevalenny <nevalenny@gmail.com> * Fix iOS framework version to 1.12.* and update Changelog * Revert lambda usage to comply with other codebase * Add error details and handling for the breaking change in iOS * Remove backend not ready from CHANGELOG * Add iOS SDK version requirement for crashes plugin
This commit is contained in:
Родитель
028b6bbfbc
Коммит
7b4e02c3f4
|
@ -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
|
||||
|
|
|
@ -60,6 +60,6 @@
|
|||
<header-file src="src/ios/AppCenterAnalyticsPlugin.h" />
|
||||
<source-file src="src/ios/AppCenterAnalyticsPlugin.m" />
|
||||
|
||||
<framework src="AppCenter" type="podspec" spec="" />
|
||||
<framework src="AppCenter" type="podspec" spec="~> 1.12.0" />
|
||||
</platform>
|
||||
</plugin>
|
||||
|
|
|
@ -69,6 +69,6 @@
|
|||
<header-file src="src/ios/CrashesUtils.h" />
|
||||
<source-file src="src/ios/CrashesUtils.m" />
|
||||
|
||||
<framework src="AppCenter" type="podspec" spec="" />
|
||||
<framework src="AppCenter" type="podspec" spec="~> 1.12.0" />
|
||||
</platform>
|
||||
</plugin>
|
||||
|
|
|
@ -85,6 +85,6 @@
|
|||
<header-file src="src/ios/PushUtils.h" />
|
||||
<source-file src="src/ios/PushUtils.m" />
|
||||
|
||||
<framework src="AppCenter/Push" type="podspec" spec="" />
|
||||
<framework src="AppCenter/Push" type="podspec" spec="~> 1.12.0" />
|
||||
</platform>
|
||||
</plugin>
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
value="com.microsoft.azure.mobile.cordova.AppCenterSharedPlugin"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
<framework src="com.microsoft.appcenter:appcenter:1.11.0" />
|
||||
<framework src="com.microsoft.appcenter:appcenter:1.11.0" />
|
||||
</platform>
|
||||
|
||||
<platform name="ios">
|
||||
|
@ -55,6 +55,6 @@
|
|||
|
||||
<header-file src="src/ios/AppCenterSharedPlugin.h" />
|
||||
<source-file src="src/ios/AppCenterSharedPlugin.m" />
|
||||
<framework src="AppCenter" type="podspec" spec="" />
|
||||
<framework src="AppCenter" type="podspec" spec="~> 1.12.0" />
|
||||
</platform>
|
||||
</plugin>
|
||||
|
|
|
@ -33,4 +33,8 @@ class AppCenterShared {
|
|||
|
||||
return AppCenterShared.appSecret;
|
||||
}
|
||||
|
||||
private static void setUserId(String userId) {
|
||||
AppCenter.setUserId(userId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Void> setUserId(final String userId) {
|
||||
final DefaultAppCenterFuture<Void> future = new DefaultAppCenterFuture<>();
|
||||
final Handler handler = new Handler();
|
||||
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
AppCenter.setUserId(userId);
|
||||
future.complete(null);
|
||||
}
|
||||
});
|
||||
|
||||
return future;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
+ (void) setAppSecret: (NSString *)secret;
|
||||
|
||||
+ (void) setUserId: (NSString *)userId;
|
||||
|
||||
+ (NSString *) getAppSecretWithSettings: (NSDictionary*) settings;
|
||||
|
||||
+ (void) configureWithSettings: (NSDictionary* ) settings;
|
||||
|
|
|
@ -12,6 +12,11 @@ static MSWrapperSdk * wrapperSdk;
|
|||
[MSAppCenter configureWithAppSecret:secret];
|
||||
}
|
||||
|
||||
+ (void) setUserId: (NSString *)userId
|
||||
{
|
||||
[MSAppCenter setUserId:userId];
|
||||
}
|
||||
|
||||
+ (NSString *) getAppSecretWithSettings: (NSDictionary*) settings
|
||||
{
|
||||
if (appSecret == nil) {
|
||||
|
|
|
@ -5,5 +5,6 @@
|
|||
|
||||
- (void)pluginInitialize;
|
||||
- (void)getInstallId:(CDVInvokedUrlCommand *)command;
|
||||
- (void)setUserId:(CDVInvokedUrlCommand *)command;
|
||||
|
||||
@end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<allow-intent href="market:*" />
|
||||
</platform>
|
||||
<platform name="ios">
|
||||
<preference name="deployment-target" value="9.0" />
|
||||
<preference name="APP_SECRET" value="paste_ios_app_secret_here" />
|
||||
<allow-intent href="itms:*" />
|
||||
<allow-intent href="itms-apps:*" />
|
||||
|
|
|
@ -117,6 +117,8 @@
|
|||
<span class="ui-disabled" id="lbl_log_level">Log level: 2</span>
|
||||
<i class="fas fa-plus ui-disabled"></i>
|
||||
</h3>
|
||||
<h3 id="user_id">User ID:</h3>
|
||||
<input type="text" id="user_id_input" />
|
||||
</div>
|
||||
|
||||
<div data-role="footer">
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче