I've implemented MC Cordova Plugin (https://github.com/salesforce-marketingcloud/MC-Cordova-Plugin) for push notification through Marketing Cloud for hybrid mobile app, but encountering problems.
On Android platform, Any functions I called from the app didn't have callback return; in iOS platform I get the callback return for isPushEnabled function, but for enablePush it is not having the callback return, and I can't get the system token when I called MCCordovaPlugin.getSystemToken .
Previously similar question here : salesforce-marketingcloud android push no
I've used Java 1.8, Cordova 7.0.0, Android Cordova v.6.3.0 but there's still not callback return (and also no error).
MC Cordova Plugin version : 1.0.2
Snippet Code :
var $j = jQuery.noConflict();
var logToConsole = cordova.require("com.salesforce.util.logger").logToConsole;
$j('#link_fetch_device_contacts').click(function() {
logToConsole("link_fetch_device_contacts clicked");
var options = new ContactFindOptions();
options.filter = ""; // empty search string returns all contacts
options.multiple = true;
options.hasPhoneNumber = true;
var fields = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
navigator.contacts.find(fields, onSuccessDevice, onErrorDevice, options);
console.log("MCCordovaPlug :");
console.log(MCCordovaPlugin);
document.addEventListener("deviceready",function(){
console.log("deviceready");
MCCordovaPlugin.isPushEnabled(function(success){
console.log("is Push Enabled Success");
console.log(success);
}, function(error){
console.log("is Push Enabled Error");
console.log(error);
});
}, false);
});
Log:
03-01 12:10:10.949 2174-2174/com.sfapp.contactexplorer I/chromium: [INFO:CONSOLE(38)] "jslog: link_fetch_device_contacts clicked", source: file:///android_asset/www/plugins/com.salesforce/www/com.salesforce.util.logger.js (38)
03-01 12:10:10.958 2174-2174/com.sfapp.contactexplorer I/chromium: [INFO:CONSOLE(15)] "MCCordovaPlug :", source: file:///android_asset/www/inline.js (15)
03-01 12:10:10.960 2174-2174/com.sfapp.contactexplorer I/chromium: [INFO:CONSOLE(16)] "[object Object]", source: file:///android_asset/www/inline.js (16)
03-01 12:10:10.960 2174-2174/com.sfapp.contactexplorer I/chromium: [INFO:CONSOLE(19)] "deviceready", source: file:///android_asset/www/inline.js (19)
03-01 12:10:10.960 2174-2682/com.sfapp.contactexplorer V/~#MCSdkCordovaPlugin: EXECUTING ACTION: isPushEnabled
03-01 12:10:10.965 2174-2682/com.sfapp.contactexplorer V/handleIsPushEnabled: org.apache.cordova.CallbackContext@4b990d2
03-01 12:10:10.971 2174-2682/com.sfapp.contactexplorer V/tryHandleIsPushEnabled: org.apache.cordova.CallbackContext@4b990d2
03-01 12:10:11.148 2174-2174/com.sfapp.contactexplorer I/chromium: [INFO:CONSOLE(38)] "jslog: onSuccessDevice: received 119 contacts", source: file:///android_asset/www/plugins/com.salesforce/www/com.salesforce.util.logger.js (38)
Edited : I have try to put Log.v in MCCordovaPlugin.java , but seems it stucked in this function :
private boolean handleIsPushEnabled(final CallbackContext callbackContext) {
Log.v("handleIsPushEnabled",callbackContext.toString());
try {
Log.v("tryHandleIsPushEnabled",callbackContext.toString());
MarketingCloudSdk.requestSdk(new MarketingCloudSdk.WhenReadyListener() {
@Override
public void ready(MarketingCloudSdk marketingCloudSdk) {
Log.v("handleIsPushEnabledSuccess",callbackContext.getCallbackId());
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, marketingCloudSdk.getPushMessageManager().isPushEnabled()));
}
});
} catch (Exception e) {
Log.v("handleIsPushEnabledError",e);
return caughtException(callbackContext, e);
}
return true;
}
There is no "handleIsPushEnabledSuccess" or "handleIsPushEnabledError" printed on logcat; directly return true.
EDITED : On Android it already works (Thanks guys for answering my question!) Now the next question is : How can I retrieve the contact key that is automatically generated from MC when we call enablePush ?
Please help about this issue.. Thanks!
Best Regards