0

In our native iOS app, I included the ServiceSDK using Cocoapods. Referring to https://developer.salesforce.com/docs/atlas.en-us.noversion.service_sdk_ios.meta/service_sdk_ios/servicesdk_ios_dev_guide.htm

Now, I want to fetch articles from Salesforce. So, I want to use the KnowledgeManager class. But as a prequisite, I need to establish the SCSServiceConfiguration object. This requires a CommunityURL.

We do not use communities in our org.

So, I use the current user's login credentials as directed here: https://developer.salesforce.com/docs/atlas.en-us.noversion.service_sdk_ios.meta/service_sdk_ios/knowledge_authenticated_user.htm

Next step, I try to fetch the data categories as directed here: https://developer.salesforce.com/docs/atlas.en-us.noversion.service_sdk_ios.meta/service_sdk_ios/ios_cache_offline.htm

I have 2 errors in XCode:

[general] Community URL appears to be configured incorrectly.
    Please refer to the Service SDK Developer's Guide for more information on configuring your organization.
    https://developer.salesforce.com/docs/atlas.en-us.noversion.service_sdk_ios.meta/service_sdk_ios/error_community.htm




load failed with error Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL, NSErrorFailingURLStringKey=//test.salesforce.com/services/data/v44.0/support/dataCategoryGroups?sObjectName=KnowledgeArticleVersion&topCategoriesOnly=false, NSErrorFailingURLKey=//test.salesforce.com/services/data/v44.0/support/dataCategoryGroups?sObjectName=KnowledgeArticleVersion&topCategoriesOnly=false, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <E6B620D0-AC3F-4FDF-996D-317D17AB2DEE>.<2>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <E6B620D0-AC3F-4FDF-996D-317D17AB2DEE>.<2>, NSUnderlyingError=0x600000047a80 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "(null)"}} [-1002]

Why would Salesforce make it mandatory to have Communities in order for us to access Knowledge from Mobile SDK?

Am i missing something? Is there a cleaner way to include and use the ServiceSDK?

**UPDATE: ** I was able to get the data categories as an authenticated user. Below is the code that worked:

In AppDelegate, didFinishLaunching API:
AuthHelper.loginIfRequired({
                    let identity: UserAccountIdentity = UserAccountManager.shared.currentUserAccountIdentity!
                    let account: UserAccount = UserAccountManager.shared.userAccount(for: identity)!
                    // Create auth settings object from SFUserAccount
                    self.scsAuthSettings = SCSAuthenticationSettings(mobileSDK: account)

                    //Set the Authentication Settings to the ServiceCloud object.
                    ServiceCloud.shared().setAuthenticationSettings(self.scsAuthSettings, forServiceType: SCServiceType.knowledge, completion: nil)
                })   

However, I am still not able to fetch articles. The code I have for fetching the articles is as below:

let km = KnowledgeManager.default
        let query = MutableArticleQuery()
        query.categories = categories
        query.queryMethod = .at
        query.pageSize = 2
        km.fetchArticles(with: query) { (articles, error) in
            if error != nil {
                print(error?.localizedDescription ?? "")
            }
            completion(articles)
        }

There is no error. But the articles always has 0 records.

0

Communities need not be turned on for accessing knowledge articles as an authenticated user. It seems so because SCSServiceConfiguration object is necessary to complete the setup and to be able to access the content. The initializer for SCSServiceConfiguration requires 3 arguments, a communityURL, a dataCategoryGroup and a rootLevelCategory.

The dataCategoryGroup and rootLevelCategory are what determines the source for artciles. So if we do not have an SCSServiceConfiguration, the APIs dont know where to look for.

The challenge was, when we dont use communities in our org, what the communityURL should be.

The answer is apiURL of the user account.
Please see the response from the mobileSDK dev team here: https://github.com/forcedotcom/ServiceSDK-iOS/issues/103.

For reference, please see the code i have used for authenticating using the logged in user's account and then creating the SCSServiceConfiguration:

AuthHelper.loginIfRequired({
                    let identity: UserAccountIdentity = UserAccountManager.shared.currentUserAccountIdentity!
                    let account: UserAccount = UserAccountManager.shared.userAccount(for: identity)!
                    // Create auth settings object from SFUserAccount
                    self.scsAuthSettings = SCSAuthenticationSettings(mobileSDK: account)

                    if let url = account.apiUrl {
                        let config = SCSServiceConfiguration(community: url, dataCategoryGroup: "Training_Content", rootDataCategory: "All")
                        ServiceCloud.shared().serviceConfiguration = config
                    }


                    //Set the Authentication Settings to the ServiceCloud object.
                    ServiceCloud.shared().setAuthenticationSettings(self.scsAuthSettings, forServiceType: SCServiceType.knowledge, completion: nil)
                })

Hope it helps!!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.