citrix / citrix-mam-sdks

The MAM SDK instrument your apps to enable enforcing policies and controls that are configured in Citrix Endpoint Management.
https://developer.cloud.com/citrixworkspace/mobile-application-integration
11 stars 4 forks source link

Using the Cordova iOS plugins with Ionic? #91

Open tatham opened 1 year ago

tatham commented 1 year ago

Just curious as to whether anyone has done any work to get the Cordova iOS plugins working in an Ionic app?

timliu55 commented 1 year ago

@tatham - Nothing about Ionic has done from Citrix. If you encounter any problems, we are happy to support.

tatham commented 1 year ago

Thanks, I’m looking at creating a wrapper for each plugin. I only need the microVPN functionality at this stage, so can I add just the core and network plugins? The Readme describes adding them all…

timliu55 commented 1 year ago

@tatham - we don't suggest that, but in theory you can remove some of them Besides CTXMAMNetwork+CTXMAMCore, you also need CTXMAMAppCore to fetch policies from CEM server, otherwise the network access policy can only be unrestricted

tatham commented 1 year ago

Thanks @timliu55, I'll include them all. I'm having a few issues, wondering whether anyone can suggest what the underlying problem might be, or how to better troubleshoot?

Our Ionic app deploys via Secure Hub. When opening the app, it switches to Secure Hub, as expected, and in the logs I see messages about the microVPN being successfully initialised (along with other MAM SDK components) and successful Secure Hub authentication.

  1. It then switches back to our Ionic app, which displays the app login page (as expected) briefly before displaying a completely white screen. I'm pretty sure this is a bug or exception being thrown, but I don't see anything relevant in the logs (and it doesn't happen when running in the Simulator.)
  2. If I minimise the app, and then resume it, the white screen is replaced by our log in screen. If I attempt to log in, I get a 'server with specified hostname could not be found'. To test that the server URL is correct, I also have a link on the login page which opens the server URL successfully using inAppBrowser. (This behaviour is the same for any of our servers on the internal network, which are only accessible if the microVPN is running.)

Attaching to the app running on the iPad from XCode has only worked once, most of the time it gives me an error about being denied :-(

Any suggestions about what might be happening, or approaches to troubleshooting?

tatham commented 1 year ago

Bit of an update:

timliu55 commented 1 year ago

@tatham Typically speaking, the error 'server with specified hostname could not be found' indicates the network plugin does not succeed to be initialized - you need to collect managed app logs from secure hub and then find below message in app logs "Network SDK is initialized."

tatham commented 1 year ago

Thanks @timliu55 Did you notice that in the situation I described, even though the login attempt fails with the 'server ... could not be found', if I then click on a link on the same login page, without doing anything else, the server URL opens without any problem? In other words, there is a subtle difference between inAppBrowser opening the URL and submitting a request to the same server as part of the login form submission. Yes, as I described: I see messages about the microVPN being successfully initialised (along with other MAM SDK components).

tatham commented 1 year ago

Another observation: when calling the initializeSDKs function, neither of the callbacks ever fires, not even if I add logging in the CtxMAMCoreBridge.js file that is part of the core plugin...

tatham commented 1 year ago

I started working on this again, as we never got it working. I'm using the recently released 23.8.0 version. I had to make a change in the CtxMAMCoreBridge.m file to get the callbacks working. (Now I'm getting the expected success or failure responses when calling initializeSDKs).

Our app uses the IBM MobileFirst plugin for authentication. The problem I'm having is that although the microVPN has successfully initialised, the login page reports 'specified hostname could not be found'.

There are two ways that I can get around this (obviously neither are acceptable):

I'm guessing that it's all about the timing of the various calls and events in the app, but I've tried everything I can think of (including sleeping for a few seconds) and it won't work the way it should.

Any suggestions about what the issue might be, or troubleshooting steps?

timliu55 commented 1 year ago

@tatham - I am not sure what happened if I cannot see the SDK logs, my suggestions are

  1. Find the Cordova sample app in the released zip, try to make it work and then check the logs diff and code diff between our sample app and your app
  2. Escalate this request to raise a support case, and supply all the detailed information you can collect
ninaDeimos commented 1 month ago

@tatham

I started working on this again, as we never got it working. I'm using the recently released 23.8.0 version. I had to make a change in the CtxMAMCoreBridge.m file to get the callbacks working. (Now I'm getting the expected success or failure responses when calling initializeSDKs).

Could you share what you changed in CtxMAMCoreBridge.m? Because I'm also not getting any callback.

tatham commented 1 month ago

@ninaDeimos

Could you share what you changed in CtxMAMCoreBridge.m? Because I'm also not getting any callback.

I'm not an Objective C programmer, and the change I made doesn't seem to be necessary, but this modified code worked for me at the time:

- (void) initializeSDKs:(CDVInvokedUrlCommand*)command {
    CTXMAMLOG_Info(CTXLog_SourceName, @"Core SDK delegate set.");
    [CTXMAMCore setDelegate:(id<CTXMAMCoreSdkDelegate>) [MAMCoreSDK sharedInstance]]; //TODO: nonnull check or log

    CTXMAMLOG_Info(CTXLog_SourceName, @"Invoking initialized sdks from plugin.");
    [CTXMAMCore initializeSDKsWithCompletionBlock: ^(NSError * nilOrError) {
        CTXMAMLOG_Info(CTXLog_SourceName, @"initializeSDKsWithCompletionBlock nilOrError : %@",[nilOrError localizedDescription]);
        if (!nilOrError) {
        [CTXMAMCore setCordovaInfoAfterBeingInitialized];
           [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId];
        }
        else {
           NSDictionary* errorInfoDict = @{ kCoreErrorCode : @(nilOrError.code), kCoreUserInfoMsg : nilOrError.localizedDescription};
            [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:errorInfoDict] callbackId:command.callbackId];
        }
    }];
}

I basically just moved the return statement into the if...else block.

ninaDeimos commented 1 month ago

@tatham Thank you. I don't understand why, but in my case it also helped. I'm getting the success callback now. But I'm still not getting the registerSdksInitializedAndReady event. Did that work for you or did you not use it?

tatham commented 1 month ago

@ninaDeimos No, registerSdksInitializedAndReady has never worked for me either, I managed to get by without it.