Added IsEnabled/SetEnabled
This commit is contained in:
Родитель
bc707c1732
Коммит
c3f09aac4d
22
README.md
22
README.md
|
@ -134,6 +134,8 @@ Once the `deviceready` event has been triggered by the Cordova framework, a `Eng
|
|||
* Engagement.sendJobEvent
|
||||
* Engagement.sendJobError
|
||||
* Engagement.sendCrash
|
||||
* Engagement.isEnabled
|
||||
* Engagement.setEnabled
|
||||
|
||||
### Engagement.startActivity
|
||||
|
||||
|
@ -223,6 +225,21 @@ Engagement.sendCrash( _crashId, _crash,[ _success], [_failure]);
|
|||
* `_crashId`: the crashid argument is a string used to identify the type of the crash.
|
||||
* `_crash`: usually the stack trace of the crash as a string.
|
||||
|
||||
### Engagement.setEnabled
|
||||
Active or deactivate the agent
|
||||
|
||||
```javascript
|
||||
Engagement.setEnabled( _enabled,[ _success], [_failure]);
|
||||
```
|
||||
##### Params
|
||||
* `_enabled`: boolean
|
||||
|
||||
### Engagement.isEnabled
|
||||
Returns the status of the agent
|
||||
|
||||
```javascript
|
||||
Engagement.isEnabled(function(_enabled){...},[_failure]);
|
||||
```
|
||||
|
||||
### Engagement.requestPermissions
|
||||
|
||||
|
@ -258,6 +275,7 @@ Engagement.getStatus( _statusCallback, [_failure]);
|
|||
console.log("AZME native Version : "+_info.nativeVersion);
|
||||
console.log("AZME plugin Version : "+_info.pluginVersion);
|
||||
console.log("Device ID : "+_info.deviceId);
|
||||
console.log("Enabled : "+_info.isEnabled);
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -266,12 +284,14 @@ History
|
|||
----
|
||||
##### 3.1.0
|
||||
* Added Windows support (Analytics only)
|
||||
* Fix `SendAppInfos` on Android
|
||||
* Added `SetEnabled`/`IsEnabled` interface
|
||||
|
||||
##### 3.0.2
|
||||
* Fixed possible duplicate notifications
|
||||
|
||||
##### 3.0.1
|
||||
* Fixed onOpenURL not being called when using a notification with no additional view
|
||||
* Fixed `onOpenURL` not being called when using a notification with no additional view
|
||||
|
||||
##### 3.0.0
|
||||
* API Breaking Change
|
||||
|
|
|
@ -36,7 +36,6 @@ module.exports = function(context) {
|
|||
var version = cfg.doc._root.attrib['version'];
|
||||
|
||||
azme_variables.APP_VERSION_NAME = version;
|
||||
azme_variables.APP_VERSION_CODE= 1;
|
||||
|
||||
var proxy = process.cwd()+"/platforms/windows/www/plugins/cordova-plugin-ms-azure-mobile-engagement/src/winjs/EngagementProxy.js";
|
||||
try {
|
||||
|
|
|
@ -266,7 +266,7 @@ public class AZME extends CordovaPlugin {
|
|||
} else if (action.equals("sendAppInfo")) {
|
||||
|
||||
try {
|
||||
String extraInfos = args.getString(1);
|
||||
String extraInfos = args.getString(0);
|
||||
EngagementShared.instance().sendAppInfo(extraInfos);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
|
@ -298,6 +298,23 @@ public class AZME extends CordovaPlugin {
|
|||
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("setEnabled")) {
|
||||
|
||||
try {
|
||||
boolean enabled = args.getBoolean(0);
|
||||
EngagementShared.instance().setEnabled(enabled);
|
||||
callbackContext.success(enabled?1:0);
|
||||
} catch (JSONException e) {
|
||||
callbackContext.error("invalid args for setEnabled");
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
else if (action.equals("isEnabled")) {
|
||||
callbackContext.success(EngagementShared.instance().isEnabled()?1:0);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
String str = "Unrecognized Command : "+action;
|
||||
EngagementShared.instance().logE(str);
|
||||
|
|
|
@ -128,9 +128,17 @@ public class EngagementShared {
|
|||
}
|
||||
|
||||
public void setEnabled(boolean _enabled) {
|
||||
logD("setEnabled:"+_enabled);
|
||||
EngagementAgent.getInstance(androidActivity).setEnabled(_enabled);
|
||||
}
|
||||
|
||||
public boolean isEnabled()
|
||||
{
|
||||
boolean b = EngagementAgent.getInstance(androidActivity).isEnabled();
|
||||
logD("isEnabled:"+b);
|
||||
return b;
|
||||
}
|
||||
|
||||
public void setDelegate(EngagementDelegate _delegate)
|
||||
{
|
||||
delegate = _delegate;
|
||||
|
|
|
@ -331,6 +331,25 @@
|
|||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
- (void)setEnabled:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
|
||||
BOOL enabled = [[command.arguments objectAtIndex:0] boolValue];
|
||||
|
||||
[[EngagementShared instance] setEnabled:enabled];
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:enabled ];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
- (void)isEnabled:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
|
||||
BOOL enabled = [[EngagementShared instance] isEnabled];
|
||||
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:enabled ];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
|
||||
// Does nothing on iOS
|
||||
- (void)requestPermissions:(CDVInvokedUrlCommand*)command
|
||||
|
|
|
@ -92,7 +92,7 @@ typedef enum {
|
|||
-(void)saveUserPreferences;
|
||||
-(void)restoreUserPreferences;
|
||||
-(void)setEnabled:(BOOL)_enabled;
|
||||
|
||||
-(BOOL) isEnabled;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -541,5 +541,14 @@ bool isStringNull(NSString*_string)
|
|||
[[EngagementAgent shared] setEnabled:_enabled];
|
||||
}
|
||||
|
||||
-(BOOL) isEnabled
|
||||
{
|
||||
BOOL b = [[EngagementAgent shared] enabled];
|
||||
if (enablePluginLog)
|
||||
NSLog( @"%@isEnabled :%d", ENGAGEMENT_LOGTAG,b);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
@ -10,31 +10,33 @@ window.azureEngagement = {
|
|||
AZME_ENABLE_NATIVE_LOG: $AZME_ENABLE_NATIVE_LOG,
|
||||
connectionString: "$AZME_WINDOWS_CONNECTION_STRING",
|
||||
appVersionName: "$APP_VERSION_NAME",
|
||||
appVersionCode: $APP_VERSION_CODE
|
||||
lastActivityName: null,
|
||||
lastActivityUserInfos: null
|
||||
};
|
||||
|
||||
function engagementLogger(_log)
|
||||
{
|
||||
function engagementLogger(_log) {
|
||||
if (window.azureEngagement.AZME_ENABLE_PLUGIN_LOG)
|
||||
console.log("[Engagement Plugin] " + _log);
|
||||
}
|
||||
|
||||
engagementLogger("AZME pluginVersion v"+window.azureEngagement.pluginVersion);
|
||||
|
||||
var script = document.createElement('script');
|
||||
script.src = "plugins/cordova-plugin-ms-azure-mobile-engagement/libs/azure-engagement.js";
|
||||
script.onload = function () {
|
||||
engagementLogger("Native Library loaded!");
|
||||
}
|
||||
document.head.appendChild(script);
|
||||
var xhrObj = new XMLHttpRequest();
|
||||
xhrObj.open('GET', "plugins/cordova-plugin-ms-azure-mobile-engagement/libs/azure-engagement.js", false);
|
||||
xhrObj.send('');
|
||||
var se = document.createElement('script');
|
||||
se.type = "text/javascript";
|
||||
se.text = xhrObj.responseText;
|
||||
document.getElementsByTagName('head')[0].appendChild(se);
|
||||
engagementLogger("JS SDK loaded");
|
||||
|
||||
cordova.commandProxy.add("Engagement",{
|
||||
|
||||
startActivity: function (successCallback, errorCallback, _params) {
|
||||
var activityName = _params[0];
|
||||
var userInfos = JSON.parse(_params[1]);
|
||||
engagementLogger("startActivity " + activityName);
|
||||
engagement.agent.startActivity(activityName , userInfos);
|
||||
window.azureEngagement.lastActivityName = _params[0];
|
||||
window.azureEngagement.lastActivityUserInfos = JSON.parse(_params[1]);
|
||||
engagementLogger("startActivity " + window.azureEngagement.lastActivityName );
|
||||
engagement.agent.startActivity( window.azureEngagement.lastActivityName , window.azureEngagement.lastActivityUserInfo);
|
||||
successCallback();
|
||||
},
|
||||
|
||||
|
@ -111,6 +113,7 @@ cordova.commandProxy.add("Engagement",{
|
|||
var status = {
|
||||
nativeVersion: azureEngagement.serviceVersion,
|
||||
pluginVersion: azureEngagement.pluginVersion,
|
||||
isEnabled : engagement.agent.isEnabled(),
|
||||
deviceId : null
|
||||
}
|
||||
engagementLogger("getStatus " + JSON.stringify(status));
|
||||
|
@ -125,9 +128,34 @@ cordova.commandProxy.add("Engagement",{
|
|||
successCallback();
|
||||
},
|
||||
|
||||
setEnabled: function (successCallback, errorCallback, _params) {
|
||||
var _enabled = _params[0];
|
||||
engagement.agent.setEnabled(_enabled);
|
||||
successCallback(engagement.agent.isEnabled());
|
||||
},
|
||||
|
||||
isEnabled: function (successCallback, errorCallback) {
|
||||
successCallback(engagement.agent.isEnabled());
|
||||
},
|
||||
|
||||
requestPermissions:function(successCallback, errorCallback) {
|
||||
engagementLogger("not supported on Windows");
|
||||
successCallback();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("deviceready",function(){
|
||||
document.addEventListener("pause", function() {
|
||||
if (azureEngagement.lastActivityName != null) {
|
||||
engagementLogger("Pausing activity " + window.azureEngagement.lastActivityName);
|
||||
engagement.agent.endActivity();
|
||||
}
|
||||
}, false);
|
||||
document.addEventListener("resume", function(){
|
||||
if (azureEngagement.lastActivityName != null) {
|
||||
engagementLogger("Resuming activity " + window.azureEngagement.lastActivityName);
|
||||
engagement.agent.startActivity(window.azureEngagement.lastActivityName, window.azureEngagement.lastActivityUserInfos);
|
||||
}
|
||||
}, false);
|
||||
|
||||
},false);
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
*/
|
||||
|
||||
|
||||
module.exports = {
|
||||
|
||||
pluginName : 'Engagement',
|
||||
|
@ -94,6 +92,14 @@ module.exports = {
|
|||
cordova.exec(_success,_failure, this.pluginName, 'sendCrash',[_crashId,_crash] );
|
||||
},
|
||||
|
||||
setEnabled: function (_enabled, _success, _failure) {
|
||||
cordova.exec(_success, _failure, this.pluginName, 'setEnabled', [_enabled]);
|
||||
},
|
||||
|
||||
isEnabled: function (_success, _failure) {
|
||||
cordova.exec(_success, _failure, this.pluginName, 'isEnabled', []);
|
||||
},
|
||||
|
||||
getStatus: function (_success,_failure) {
|
||||
cordova.exec(_success,_failure, this.pluginName, 'getStatus', [] );
|
||||
},
|
||||
|
@ -104,5 +110,3 @@ module.exports = {
|
|||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче