Skip to content

Commit 6c7fe3f

Browse files
committed
Expose error values as string and improve readme
1 parent 5640167 commit 6c7fe3f

File tree

2 files changed

+108
-2
lines changed

2 files changed

+108
-2
lines changed

README.md

+76-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,76 @@
1-
# sdk-swift-ui
1+
# Trinsic Swift UI Library
2+
3+
[![Swift UI Version](https://img.shields.io/cocoapods/v/TrinsicUI.svg)](<[https://www.npmjs.org/package/@trinsic/react-native-ui](https://cocoapods.org/pods/TrinsicUI)>) [![Swift Build Status](https://github.com/trinsic-id/sdk/actions/workflows/ui-swift-release.yml/badge.svg)](https://github.com/trinsic-id/sdk/actions?query=branch%main)
4+
5+
The Trinsic Swift UI Library provides ways to launch verification sessions directly in your Swift and Objective-C projects, requiring very little code.
6+
7+
You can find a full example using this library in the [samples](https://github.com/trinsic-id/sdk/tree/main/ui-swift/samples) folder.
8+
9+
## Documentation
10+
11+
See the [Trinsic docs](https://docs.trinsic.id/docs/) for more detailed information on how to start integrating with our identity acceptance network.
12+
13+
## Installation
14+
15+
### Swift package manager
16+
17+
Add the Trinsic repository `https://github.com/trinsic-id/sdk-swift-ui` as a dependency.
18+
19+
### CocoaPods
20+
21+
Add a reference to the `TrinsicUI` pod to your `Podfile` with the latest version (see the shield at the top of the readme) and run `pod install`
22+
23+
```
24+
pod 'TrinsicUI', '~> [latest version]'
25+
```
26+
27+
## Setup
28+
29+
### Choose a Custom Scheme
30+
31+
This library makes use of `ASWebAuthenticationSession` on iOS and macOS.
32+
33+
Therefore, you must register a custom scheme against your app on both iOS and macOS in order for the library to be able to capture the results of a session.
34+
35+
This custom scheme **should be globally unique to your organization and application**.
36+
37+
An example of a good custom scheme might be `acme-corp-shopping-app-trinsic`.
38+
39+
#### Add the scheme to your app's URLs
40+
41+
Select your app's target and on the info tab in XCode add the scheme you selected.
42+
43+
## Usage
44+
45+
Import TrinsicUI into your view:
46+
47+
```swift
48+
import TrinsicUI
49+
```
50+
51+
Create an instance of TrinsicUI and launch a session.
52+
You can retrieve the launch url from a trusted backend that can reach out to the Trinsic servers. [See our backend language examples](https://github.com/trinsic-id/sdk/tree/main/api-typescript/samples).
53+
54+
```swift
55+
let trinsicUI = TrinsicUI()
56+
let result = try await trinsicUI.launchSession(launchUrl: "[REPLACE_ME]", callbackURL: "[REPLACE_ME]")
57+
```
58+
59+
## SDK Versioning
60+
61+
var configuration = new Configuration { AccessToken = "your-access-token" };
62+
63+
var attachments = new AttachmentsApi(configuration);
64+
var network = new NetworkApi(configuration);
65+
var sessions = new SessionsApi(configuration);
66+
67+
## Support
68+
69+
Any issues, inquiries, and feature requests can be sent to [[email protected]](mailto:[email protected]), or feel free to open a GitHub issue [here](https://github.com/trinsic-id/sdk/issues).
70+
71+
## More Information
72+
73+
- [API Reference](https://docs.trinsic.id/reference)
74+
- [Developer Guide](https://docs.trinsic.id/docs/developer-tools)
75+
- [Our Blog](https://trinsic.id/blog/)
76+
- [Schedule a demo](https://trinsic.id/contact/)

Sources/TrinsicUI/TrinsicError.swift

+32-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,39 @@ import Foundation
2121
@objc public class TrinsicError: NSObject {
2222
@objc public static func error(with code: TrinsicErrorCode, message: String? = nil) -> NSError {
2323
let domain = "id.trinsic.TrinsicError"
24-
let errorDescription = "\(String(describing: code)): \(message ?? "")"
24+
let errorDescription = "\(description(for: code)): \(message ?? "")"
2525
let userInfo = [NSLocalizedDescriptionKey: errorDescription]
2626
return NSError(domain: domain, code: code.rawValue, userInfo: userInfo)
2727
}
28+
29+
@objc private static func description(for code: TrinsicErrorCode) -> String {
30+
switch code {
31+
case .unknownError:
32+
return "Unknown error occurred."
33+
case .unparsableResultUrl:
34+
return "The result URL could not be parsed."
35+
case .couldNotAcquireRootViewController:
36+
return "Could not acquire the root view controller."
37+
case .unsupportedIosVersion:
38+
return "Unsupported iOS version."
39+
case .noRegisteredApplicationForLaunchUrl:
40+
return "No registered application for the launch URL."
41+
case .unparsableLaunchUrl:
42+
return "The launch URL could not be parsed."
43+
case .missingSessionId:
44+
return "The session ID is missing."
45+
case .noSupportForiOSBelow12:
46+
return "This feature is not supported on iOS below version 12."
47+
case .emptyLaunchUrl:
48+
return "The launch URL is empty."
49+
case .emptyRedirectUrl:
50+
return "The redirect URL is empty."
51+
case .cannotReconstructLaunchUrl:
52+
return "Cannot reconstruct the launch URL."
53+
case .unparsableCallbackUrl:
54+
return "The callback URL could not be parsed."
55+
case .unsupportedHttpsLinking:
56+
return "HTTPS linking is not supported."
57+
}
58+
}
2859
}

0 commit comments

Comments
 (0)