Cadre de travail NowData : iOS
Le cadre de travail NowData contient des méthodes qui activent l’instanciation des services NowData, telles que NowGraphQLService, NowTableService, NowAPIService (pour les API personnalisées) et NowAttachmentService.
NowData : makeApiService(instanceUrl : URL, path : String, completion : @escaping (Result<NowApiService, NowServiceError>) -> Void))
Crée une instance de NowApiService et, une fois terminée, appelle le gestionnaire de complétion spécifié.
| Nom | Type | Description |
|---|---|---|
| instanceUrl | URL | URL de l’instance dont les ServiceNow API REST doivent être accessibles par le service. |
| chemin d'accès | Chaîne | Chemin d’accès de l’API. Par exemple, si l’appel d’API est |
| achèvement | @escaping ((Result<NowApiService, NowServiceError>) -> Void) | Gestionnaire de complétion appelé avec un Result<NowApiService, NowServiceError> contenant soit une instance NowApiService initialisée, soit une NowServiceError indiquant pourquoi l’initialisation a échoué. |
| Type | Description |
|---|---|
| Aucun |
L’exemple de code suivant montre comment appeler cette fonction.
let path = "api/now/sg"
let apiPublisher = apiService(for: path)
func apiService(for path: String) -> AnyPublisher<NowAPIService, ConfigurationError> {
guard let instanceURL else {
return Fail(error: ConfigurationError.invalidInstanceURL)
.eraseToAnyPublisher()
}
return Future { promise in
NowData.makeApiService(instanceUrl: instanceURL, path: path) { (result) in
promise(result.mapError { .sdkError($0) })
}
}
.eraseToAnyPublisher()
}
NowData : makeAttachmentService(instanceUrl : URL, complétion : @escaping (Result<NowAttachmentService, NowServiceError>) -> Void))
Crée une instance de NowAttachmentService et, une fois l’opération terminée, appelle le gestionnaire de complétion spécifié.
| Nom | Type | Description |
|---|---|---|
| instanceUrl | URL | URL de l’instance dont les ServiceNow pièces jointes doivent être accessibles par le service. |
| achèvement | @escaping (Result<NowAttachmentService, NowServiceError>) -> Void) | Gestionnaire de complétion appelé avec un Result<NowAttachmentService, NowServiceError> contenant soit une instance NowAttachmentService initialisée, soit un NowServiceError indiquant pourquoi l’initialisation a échoué. |
| Type | Description |
|---|---|
| Aucun |
L’exemple de code suivant montre comment appeler cette fonction.
….
guard
let jwtUrl = URL(string: "http://13.57.38.237:8080"),
let instanceUrl = URL(string: "https://mobilecoresdk.service-now.com") else {
return
}
// AuthorizationProvider – struct conforming to NowSDKAuthorizationProviding protocol
let authorizationProvider = AuthorizationProvider(userEmail: "sdk@servicenow.com", jwtProviderUrl: jwtUrl, clientId: "deb8756b452d201039231ca568f26511")
// PermissionProvider – class conforming to DevicePermissionDelegate protocol
let permissionProvider = PermissionProvider()
let config = NowSDKConfiguration(authorizationProvider: authorizationProvider, permissionDelegate: permissionProvider, logLevel: .debug)
do {
try NowSDK.configure(with: config)
initializeAttachmentService (with: instanceURL)
} catch {
// Return ConfigurationError.sdkError(error)
}
…..
func initializeAttachmentService(instanceUrl: instanceURL) { result in
switch result {
case .success(let service)
self?.attachmentService = service
case .failure(let error)
debug.print(“Creating Attachment service failed with error: \(error.localizedDescription)”)
self?.attachmentService = nil
}
}
NowData : makeGraphQLService(instanceUrl : URL, complétion : @escaping ((Result<NowGraphQLService, NowServiceError>) -> Void))
Crée une instance de NowGraphQLService et, une fois terminée, appelle le gestionnaire de complétion spécifié.
| Nom | Type | Description |
|---|---|---|
| instanceUrl | URL | URL de l’instance ServiceNow fournissant les services GraphQL. |
| achèvement | @escaping ((Result<NowGraphQLService, NowServiceError>) -> Void) | Gestionnaire de complétion appelé avec un Result<NowGraphQLService, NowServiceError> contenant soit une instance NowGraphQLService initialisée, soit une NowServiceError indiquant pourquoi l’initialisation a échoué. |
| Type | Description |
|---|---|
| Aucun |
func initializeGraphQLService(instanceUrl: URL) {
makeGraphQLService(instanceUrl: instanceUrl) { [weak self] result in
switch result {
case .success(let service):
self?.graphQLService = service
case .failure(let error):
debugPrint("Creating GraphQL service failed with error: \(error.localizedDescription)")
self?.graphQLService = nil
}
}
}
NowData : makeTableService(instanceUrl : URL, complétion : @escaping (Result<NowTableService, NowServiceError>) -> Void))
Crée une instance de NowTableService et, une fois l’opération terminée, appelle le gestionnaire de complétion spécifié.
| Nom | Type | Description |
|---|---|---|
| instanceUrl | URL | URL de l’instance dont les ServiceNow tables doivent être accessibles par le service. |
| achèvement | @escaping ((Result<NowTableService, NowServiceError>) -> Void) | Gestionnaire de complétion appelé avec un Result<NowTableService, NowServiceError> contenant soit une instance NowTableService initialisée, soit une NowServiceError indiquant pourquoi l’initialisation a échoué. |
| Type | Description |
|---|---|
| Aucun |
L’exemple de code suivant montre comment appeler cette fonction.
func initializeTableService(for instanceUrl: URL) {
makeTableService(instanceUrl: instanceUrl) { [weak self] result in
guard let self = self else { return }
switch result {
case .success(let tableService):
self.tableService = tableService
// Create a Paginator that will iterate over pages of customer support cases. The Paginator's response type will be
// inferred from the Paginator's type definition (e.g. `Paginator<[CustomerServiceCase]>`).
self.paginator = tableService.paginator(from: Self.tableName, configuration: self.fetchConfiguration)
// Subscribe to the Paginator's publisher so we will be able to receive paged results.
self.subscribeToPaginatorPublisher()
// As we are now ready to start fetching data, inform the view controller.
self.onReady(self)
case .failure(let error):
debugPrint("Creating table service failed with error: \(error.localizedDescription)")
self.tableService = nil
self.paginator = nil
}
}
}