portal.fetchLicenseInfo completion closure is not invoked.

556
3
Jump to solution
09-23-2021 04:35 PM
ShiminCai
Occasional Contributor III

Hi All,

I'm checking out an ArcGIS Runtime license from our ArcGIS Online account using the code below that is copied from ArcGIS Runtime SDK for iOS documentation:

//get the users license info from the portal

portal.fetchLicenseInfo { (licenseInfo,error) in

    guard let error = error {

        print("Error fetching user's licenses... \(error)")

        return

    }

    //set the license using the Named User's licenseInfo

    do {

        let result = try AGSArcGISRuntimeEnvironment.setLicenseInfo(licenseInfo!)

    } catch let error as NSError {

        print("error: \(error.localizedDescription)")

    }

    //The app is now licensed

    // Save the license information so that the app can be started and licensed offline

    // In this example the licenseDictionary is stored in keychain

    var licenseDictionary: NSDictionary?

    do {

        licenseDictionary = try licenseInfo?.toJSON() as! NSDictionary?

    } catch {

        print("LicenseInfo not available")

    }

    let keychainItem = AGSKeychainItem(identifier: "com.your_org.your_app_name", accessGroup: nil, acrossDevices: false)

    keychainItem.writeObject(toKeychain: licenseDictionary!, completion: { (writeError) in

        if let error = writeError {

            print("Error writing to the Keychain... \(error)")

        }

    })

 

The problem is that the completion closure of the portal.fetchLicenseInfo() method never gets invoked and as a result I never get a license or an error...

However, I can get a valid license from the portal property: portal.portalInfo?.licenseInfo, but 'licenseInfo' is deprecated: This property has been replaced by `AGSPortal#fetchLicenseInfoWithCompletion:` from Xcode.

Does anybody have any idea please? I'm using SDK 100.10.

Thanks,

Shimin

0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

Are you holding on to the `portal` instance? If it gets deallocated before the round trip to the server, then the completion handler won't get called. Can you make it an instance variable?

View solution in original post

0 Kudos
3 Replies
Nicholas-Furness
Esri Regular Contributor

Are you holding on to the `portal` instance? If it gets deallocated before the round trip to the server, then the completion handler won't get called. Can you make it an instance variable?

0 Kudos
ShiminCai
Occasional Contributor III

Thanks Nick for your reply. I don't think the portal variable is deallocated because I can get a valid license from portal.portalInfo.licenseInfo. I'll try to make it an instance variable...

0 Kudos
ShiminCai
Occasional Contributor III

Hi Nick,

Making it an instance variable helped. Thank you so much for your help.

Cheers,

Shimin

0 Kudos