SMP SDK for iOS for development on Swift

527 Views Asked by At

How to establish connection to SMP server through sdk for ios development (Swift language).

I have sample odataconnection file modified with necessary configurations like connection, host, port and domain and security profile. But that is for objectiveC based.

Requesting similar sample code for swift so that I can establish device registration and user logon in SMP

Thanks, Rajkamal

1

There are 1 best solutions below

2
Michael Jess On

Have you tried our Tutorials yet? Essentially, what you need is the right set of connection settings:

struct Constants {
    // The appID is the unique identifier of the application.
    // It must be the the same ID as on the server, but it may be different
    // from the bundle identifier of your application.
    //  static let appID = "com.sap.mit.native.intermediate.logon"
    private static let sapcpmsURLString = "https://mobile-a326aab34.hana.ondemand.com/"
    static let sapcpmsURL = URL(string: sapcpmsURLString)!
    static let appURL = sapcpmsURL.appendingPathComponent(appID)
    static let samlAuthURL = URL(string: "\(sapcpmsURL.absoluteString)SAMLAuthLauncher")!
    static let samlFinishURL = URL(string: "\(sapcpmsURL.absoluteString)SAMLAuthLauncher?finishEndpointParam=someUnusedValue")!
}

Then register as follows (assuming SAML authentication):

public func authenticate(completionHandler: @escaping (_ error: Error?) -> Void) {
    // this starts a SAML authentication against the SAP Cloud Platform if successfull it will be registered to the current urlSession
    // let samlAuthenticationParameters = SAMLAuthenticationParameters(authorizationEndpointURL: Constants.samlAuthURL, finishEndpointURL: Constants.samlFinishURL)
    let samlAuthenticator = SAMLAuthenticator(authenticationParameters: samlAuthenticationParameters)
    let samlObserver = SAMLObserver(authenticator: samlAuthenticator)
    urlSession.register(samlObserver)

    samlAuthenticator.authenticate(completionHandler: completionHandler)
}