NowWeb API - iOS
The NowWeb API is a top-level global API that enables uses to instantiate a NowWeb service instance.
NowWeb - makeWebService(instanceUrl: URL) async throws
Creates an instance of NowWebService using the previously specified configuration.
You must initialize the SDK prior to calling this function or the completion block is called with a sdkNotConfigured error. To initialize the SDK, call NowSDK.configure() with the desired
configuration.
| Name | Type | Description |
|---|---|---|
| instanceUrl | URL | URL of the ServiceNow instance whose web services are to be accessed by the service. |
| Type | Description |
|---|---|
| NowWebService | If successful, returns an initialized NowWebService object. |
| NowServiceError | Throws one of the following errors if the method fails. Possible values:
|
The following code example shows how to call this method.
do {
let service = try await NowWeb.makeWebService(instanceUrl: instanceUrl)
self.webService = service
} catch {
debugPrint("Web Service creation failed with error: \(error.localizedDescription)")
}
NowWeb - makeWebService(instanceUrl: URL, completion: @escaping ((Result<NowWebService, NowServiceError>) -> Void))
Creates an instance of NowWebService using the previously specified configuration. When finished, calls the specified completion handler.
You must initialize the SDK prior to calling this function or the completion block is called with a sdkNotConfigured error. To initialize the SDK, call NowSDK.configure() with the desired
configuration.
| Name | Type | Description |
|---|---|---|
| instanceUrl | URL | URL of the ServiceNow instance whose web services are to be accessed by the service. |
| completion | @escaping ((Result<NowWebService, NowServiceError>) -> Void) | Completion handler that is called with a Result<NowWebService, NowServiceError> containing either an initialized NowWebService instance or a NowServiceError
indicating why the initialization failed. |
| Type | Description |
|---|---|
| None |
func initializeNowSDK(userEmail: String) {
currentUser = userEmail
let sdkConfig = NowSDKConfiguration(authorizationProvider: self, permissionDelegate: self, logLevel: .debug)
do {
try NowSDK.configure(with: sdkConfig)
configureAnalytics()
} catch {
debugPrint("Could not initialize NowSDK. Error: \(error.localizedDescription)")
}
}
NowWeb - makeWebService(instanceUrl: URL)
Creates an instance of NowWebService using the previously specified configuration.
You must initialize the SDK prior to calling this function or the completion block is called with a sdkNotConfigured error. To initialize the SDK, call NowSDK.configure() with the desired
configuration.
| Name | Type | Description |
|---|---|---|
| instanceUrl | URL | URL of the ServiceNow instance whose web services are to be accessed by the service. |
| Type | Description |
|---|---|
| AnyPublisher<NowWebService, NowServiceError> | If successful, returns an initialized NowWebService object. If it fails, returns a NowServiceError object. |
func initializeWebService() {
NowWeb.makeWebService(instanceUrl: instanceUrl)
.sink { completion in
if case .failure(let error) = completion {
debugPrint("Web Service creation failed with error: \(error.localizedDescription)")
}
} receiveValue: { [weak self] service in
self?.webService = service
}
.store(in: &subscriptions)
}