SCSKnowledgeManager


@interface SCSKnowledgeManager : NSObject

A SCSKnowledgeManager object is used to interact with knowledge data such as category groups, categories, and articles.

The knowledge manager abstracts the storage, network retrieval, and queries for interacting with data in an efficient fashion. You can use this object to fetch categories and articles from your org. Once fetched, you can use this object to get cached content. See the SCSArticleQuery class for an explanation on how to query for content.

The knowledge manager caches data for offline use, allowing categories and articles to be used even when no network is available. To stay informed about important changes in the underlying data model, any changes to the underlying categories will be advertised through the use of the following notifications:

The object of the notification will be the SCSKnowledgeManager instance itself, while the category in question is stored in the notification’s userInfo dictionary under the SCSKnowledgeManagerCategoryKey key.

  • Authentication settings used for network interactions and offline caching.

    This value will change if the +defaultManager instance is used.

    See

    +defaultManager

    Declaration

    Objective-C

    @property (readonly, strong, nonatomic)
        SCSAuthenticationSettings *_Nonnull authenticationSettings;

    Swift

    var authenticationSettings: SCSAuthenticationSettings { get }
  • Singleton instance of the knowledge manager.

    This singleton instance automatically uses the user account currently selected within SCServiceCloud.account.

    Declaration

    Objective-C

    @property (readonly, strong, atomic, class)
        SCSKnowledgeManager *_Nonnull defaultManager;

    Swift

    class var `default`: KnowledgeManager { get }

    Return Value

    Shared knowledge manager instance.

  • Returns a knowledge manager instance with the given user account.

    Declaration

    Objective-C

    + (nullable SCSKnowledgeManager *)knowledgeManagerWithAuthenticationSettings:
        (nonnull SCSAuthenticationSettings *)authenticationSettings;

    Swift

    /*not inherited*/ init?(authenticationSettings: SCSAuthenticationSettings)

    Parameters

    authenticationSettings

    Authentication settings to use.

    Return Value

    Initialized knowledge manager.

  • Triggers a fetch to load the categories for the user’s organization.

    The data returned will automatically be cached, and any changes that have occurred since the previous fetch will be updated.

    Declaration

    Objective-C

    - (void)fetchAllCategoriesWithCompletionHandler:
        (nullable void (^)(NSArray<SCSCategoryGroup *> *_Nullable __strong,
                           NSError *_Nullable __strong))completionHandler;

    Swift

    func fetchAllCategories(completionHandler: (([SCSCategoryGroup]?, Error?) -> Void)? = nil)

    Parameters

    completionHandler

    Optional completion block to be called when the operation completes.

  • Indicates whether this knowledge manager has fetched new category information since it was created.

    Note

    It is not always necessary to fetch new categories, especially since that may be a costly operation to perform if your organization has a large number of categories.

    Declaration

    Objective-C

    - (BOOL)hasFetchedCategories;

    Swift

    func hasFetchedCategories() -> Bool

    Return Value

    YES if this instance has successfully completed -fetchAllCategoriesWithCompletionHandler:, otherwise NO.

  • Indicates whether this knowledge manager has determined the supported languages since it was created.

    Note

    It is not always necessary to fetch the list, it may be a costly operation it does not need to be done more than once.

    Declaration

    Objective-C

    - (BOOL)hasFetchedSupportedLanguages;

    Swift

    func hasFetchedSupportedLanguages() -> Bool

    Return Value

    YES if this instance has successfully completed -fetchKnowledgeSupportedLanguagesWithCompletionHandler:, otherwise NO

  • Returns all the public category groups for the current organization.

    Warning

    This array may be empty if no data has been previously cached.

    Declaration

    Objective-C

    - (nonnull NSArray<SCSCategoryGroup *> *)allCategoryGroups;

    Swift

    func allCategoryGroups() -> [SCSCategoryGroup]

    Return Value

    Array of SCSCategoryGroup instances

  • Returns the category group matching the given name.

    Warning

    This may return nil if no data has been previously cached.

    Declaration

    Objective-C

    - (nullable SCSCategoryGroup *)categoryGroupWithName:(nonnull NSString *)name;

    Swift

    func categoryGroup(withName name: String) -> SCSCategoryGroup?

    Parameters

    name

    Name of the category group to return.

    Return Value

    SCSCategoryGroup instance, or nil if none is found with that name.

  • Returns a cached article object with the given article ID.

    Declaration

    Objective-C

    - (nullable SCSArticle *)
        articleWithId:(nonnull NSString *)articleIdOrName
                error:(NSError *__autoreleasing _Nullable *_Nullable)error;

    Swift

    func article(withId articleIdOrName: String, error: ()) throws -> SCSArticle

    Parameters

    articleIdOrName

    Article ID or URL Name to search for.

    error

    Optional pointer to an error variable.

    Return Value

    SCSArticle matching the given ID, or nil if no article is found in the cache with that name.

  • Undocumented

    Declaration

    Objective-C

    - (nullable SCSArticle*)articleWithId:(NSString*)articleId SCS_API_DEPRECATED_WITH_REPLACEMENT("articleWithId:error:");

    Swift

    func article(withId articleId: String) -> SCSArticle?
  • Returns cached article objects matching the given query.

    This method searches through the database of existing article information stored locally to identify articles. No network operations are invoked through this method, and this can safely be used even when offline.
    For performing requests against the network, please see the -fetchArticlesWithQuery:completion: method

    Note

    This ignores the pageSize and pageNumber properties, instead returning all locally-cached articles matching the remaining query parameters.

    Declaration

    Objective-C

    - (void)articlesMatchingQuery:(nonnull SCSArticleQuery *)query
                       completion:(nonnull void (^)(
                                      NSArray<SCSArticle *> *_Nullable __strong,
                                      NSError *_Nullable __strong))completion;

    Swift

    func articles(matching query: SCSArticleQuery, completion: @escaping ([SCSArticle]?, Error?) -> Void)

    Parameters

    query

    Query to use for identifying articles.

    completion

    Completion block to invoke when the articles are found.

  • Fetches articles from the server that match the given query.

    Declaration

    Objective-C

    - (void)fetchArticlesWithQuery:(nonnull SCSArticleQuery *)query
                        completion:(nullable void (^)(
                                       NSArray<SCSArticle *> *_Nonnull __strong,
                                       NSError *_Nullable __strong))completion;

    Swift

    func fetchArticles(with query: SCSArticleQuery, completion: (([SCSArticle], Error?) -> Void)? = nil)

    Parameters

    query

    Query to use for identifying articles.

    completion

    Completion block to invoke when articles are found.

  • Clear the cache data from the disk if the cache exists on the disk.

    Declaration

    Objective-C

    - (void)deleteCacheIfExists:
        (nonnull void (^)(NSError *_Nullable __strong))completion;

    Swift

    func deleteCacheIfExists(_ completion: @escaping (Error?) -> Void)

    Parameters

    completion

    Completion block to invoke when deletion of the cache is completed or if an error occurs.

  • Fetches the supported languages for knowledge.

    Declaration

    Objective-C

    - (void)fetchSupportedLanguagesWithCompletion:
        (nullable void (^)(NSArray<NSString *> *_Nullable __strong,
                           NSError *_Nullable __strong))completion;

    Swift

    func fetchSupportedLanguages(completion: (([String]?, Error?) -> Void)? = nil)

    Parameters

    completion

    Completion block to invoke when the supported languages have been recieved from the org or an error occurs.