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:
SCSKnowledgeManagerCategoryAddedNotification
– A new category is added.SCSKnowledgeManagerCategoryUpdatedNotification
– A category has been modified (e.g. title, child categories, etc)SCSKnowledgeManagerCategoryDeletedNotification
– A category has been deleted.
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 (nonatomic, strong, readonly) 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 (class, strong, readonly) NS_SWIFT_NAME(default) SCSKnowledgeManager *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() async throws -> [SCSCategoryGroup]
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:
, otherwiseNO
. -
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:
, otherwiseNO
-
Returns all the public category groups for the current organization.
Warning
This array may be empty if no data has been previously cached.
See
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.See
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, ornil
if none is found with that name. -
Returns a cached article object with the given article ID.
See
Declaration
Objective-C
- (nullable SCSArticle *) articleWithId:(nonnull NSString *)articleIdOrName error:(NSError *_Nullable __autoreleasing *_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, ornil
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:
methodNote
This ignores the
pageSize
andpageNumber
properties, instead returning all locally-cached articles matching the remaining query parameters.See
See
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) async throws -> [SCSArticle]
Parameters
query
Query to use for identifying articles.
completion
Completion block to invoke when the articles are found.
-
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) async throws -> [SCSArticle]
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() async throws
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() async throws -> [String]
Parameters
completion
Completion block to invoke when the supported languages have been recieved from the org or an error occurs.