iOS
iOS is a mobile operating system created and developed by Apple Inc. exclusively for its hardware.

Let's Get your iOS App running with SAWO
πŸ™Œ

Steps

iOS CocoaPod Integration

1 iOS CocoaPod Integration
2. Choose app in app templates.
3. Add unique Bundle Identifier.
4. Create an Apple Developer account ID and login.
5. Select Identifiers and click + icon.
6. Select App IDs in Certificates, Identifiers & Profiles Tab.
7. Select App as a type.
8. Add your bundle ID mentioned in the project created and description. Now select App groups in the capabilities.
9. Go to signing and capabilities and select teams with apple developer account linked to it and. Click on capabilities button
10. Select app groups in capabilities.
11. Add App group - β€œ ”
12. To use SAWO Login you would need an API key which can be obtained by creating a project in the sawo dashboard.
13. Copy the API key from the project and keep it safe and secure.
The best practice to store your API key is to store values in .env so that they are not exposed.
14. SawoFramework is available through CocoaPods.
15. Create a new Xcode Project with a View Controller and create a login button and its action in the ViewController.swift file.
16. Open your project folder in terminal and type in 'pod init', then open the pod file of your project and add the following line to the pod file and save it.
1
pod 'SawoFramework
Copied!
17. Now go back to the terminal and type pod install to install the pod to your project. Once the pod has been installed xcworkspace file of your project and work on it.
18. Import the Framework and pod by adding following code.
1
import UIKit
2
import SawoFramework
Copied!
19. Add the following snippet above viewDidLoad func
1
let VC = SawoFramework.LoginViewController()
2
var PayloadApi = ""
3
​
4
var publicKeyApp = ""
5
var privateKeyApp = ""
6
var sessionIdApp = ""
7
​
8
9
var keychainPublicKEY = ""
10
var keychainPrivateKEY = ""
11
var keychainSessionID = ""
Copied!
20. Add the following code snippet in your @IBAction func of the button
1
self.present(self.VC, animated: true, completion: nil)
2
​
3
let apiKey = ["apikey": "ADD-API-KEY-HERE"]
4
let identifierType = ["identifier": "ADD-IDENTIFIER-HERE"]
5
let secretKey = ["secretkey": "ADD-SECRET-KEY-HERE"]
6
7
​
8
var userDefaults = UserDefaults(suiteName: "group.Trusted.SawoLabs.onesignal")
9
if let testpublicKEY = userDefaults?.object(forKey: "publicKEY") as? String {
10
//print("publicKEY : \(testpublicKEY)")
11
keychainPublicKEY = testpublicKEY
12
}
13
if let testprivateKEY = userDefaults?.object(forKey: "privateKEY") as? String {
14
//print("publicKEY : \(testprivateKEY)")
15
keychainPrivateKEY = testprivateKEY
16
}
17
if let testsessionID = userDefaults?.object(forKey: "sessionID") as? String {
18
//print("publicKEY : \(testsessionID)")
19
keychainSessionID = testsessionID
20
}
21
22
let keychainPuK = ["keychainPuk": "\(String( keychainPublicKEY ))"]
23
let keychainPrK = ["keychainPrk": "\(String( keychainPrivateKEY ))"]
24
let keychainSess = ["keychainSess": "\(String( keychainSessionID ))"]
25
​
26
​
27
NotificationCenter.default.post(name: Notification.Name("ProductKey"), object: nil,userInfo: apiKey)
28
NotificationCenter.default.post(name: Notification.Name("IdentifierType"), object:nil, userInfo: identifierType)
29
NotificationCenter.default.post(name: Notification.Name("SecretType"), object:nil, userInfo: secretKey)
30
NotificationCenter.default.post(name: Notification.Name("keychainPuKFramework"), object: nil,userInfo: keychainPuK)
31
NotificationCenter.default.post(name: Notification.Name("ProductKeyFramework"), object: nil,userInfo: keychainPrK)
32
NotificationCenter.default.post(name: Notification.Name("keychainSessFramework"), object: nil,userInfo: keychainSess)
33
​
34
NotificationCenter.default.addObserver(self, selector: #selector(SessionIDApp(_:)), name: Notification.Name("sessionId"), object: nil)
Copied!
21. The following code in viewDidLoad func
1
NotificationCenter.default.addObserver(self, selector: #selector(WebViewError(_:)), name: Notification.Name("WebViewError"), object: nil)
2
NotificationCenter.default.addObserver(self, selector: #selector(LoginIsApproved(_:)), name: Notification.Name("LoginApproved"), object: nil)
3
NotificationCenter.default.addObserver(self, selector: #selector(loginCONTENTapi(_:)), name: Notification.Name("PayloadOfUser"), object: nil)
4
​
5
NotificationCenter.default.addObserver(self, selector: #selector(PublicKEYApp(_:)), name: Notification.Name("publickey"), object: nil)
6
NotificationCenter.default.addObserver(self, selector: #selector(PrivateKEYApp(_:)), name: Notification.Name("privatekey"), object: nil)
7
NotificationCenter.default.addObserver(self, selector: #selector(SessionIDApp(_:)), name: Notification.Name("sessionId"), object: nil)
8
​
9
NotificationCenter.default.addObserver(self, selector: #selector(loginButtonWebView(_:)), name: Notification.Name("loginButtonPressed"), object: nil)
10
​
Copied!
22. Add a new View Controller to which you want to take your user after login. Create a Segue to this View Controller and select its type as present modally. Inside Attributes inspector in presentation select full screen and give the segue a name in identifier.
23. Add the snippet below viewDidLoad func
1
@objc func loginButtonWebView(_ notification: Notification){
2
// DispatchQueue.main.asyncAfter(deadline: .now() + 6.0) {
3
// self.dismiss(animated: true, completion: nil)
4
// }
5
// performSegue(withIdentifier: "InternetError", sender: nil)
6
}
7
​
8
​
9
@objc func LoginIsApproved(_ notification: Notification){
10
print("Login was Successful")
11
self.dismiss(animated: true, completion: nil)
12
performSegue(withIdentifier: "Sawo", sender: nil)
13
}
14
​
15
​
16
@objc func loginCONTENTapi(_ notification: Notification){
17
if let data = notification.userInfo as? [String: String]
18
{
19
for (UserPayload, Content) in data
20
{
21
PayloadApi = Content
22
print("\(UserPayload) : \(Content) ")
23
}
24
}
25
​
26
}
27
​
28
@objc func PublicKEYApp(_ notification: Notification){
29
if let data = notification.userInfo as? [String: String]
30
{
31
for (PublicKEYApps, valuePublic) in data
32
{
33
publicKeyApp = valuePublic
34
print("\(PublicKEYApps) : \(valuePublic) ")
35
var userDefaults = UserDefaults(suiteName: "group.Trusted.SawoLabs.onesignal")!
36
userDefaults.set("\(valuePublic)", forKey: "publicKEY")
37
userDefaults.synchronize()
38
​
39
}
40
}
41
}
42
​
43
@objc func PrivateKEYApp(_ notification: Notification){
44
if let data = notification.userInfo as? [String: String]
45
{
46
for (PrivateKEYApps, valuePrivate) in data
47
{
48
privateKeyApp = valuePrivate
49
print("\(PrivateKEYApps) : \(valuePrivate) ")
50
var userDefaults = UserDefaults(suiteName: "group.Trusted.SawoLabs.onesignal")!
51
userDefaults.set("\(valuePrivate)", forKey: "privateKEY")
52
userDefaults.synchronize()
53
​
54
}
55
}
56
}
57
​
58
@objc func SessionIDApp(_ notification: Notification){
59
if let data = notification.userInfo as? [String: String]
60
{
61
for (SessionIDApps, valueSessionID) in data
62
{
63
sessionIdApp = valueSessionID
64
print("\(SessionIDApps) : \(valueSessionID) ")
65
var userDefaults = UserDefaults(suiteName: "group.Trusted.SawoLabs.onesignal")!
66
userDefaults.set("\(valueSessionID)", forKey: "sessionID")
67
userDefaults.synchronize()
68
​
69
}
70
71
}
72
73
​
74
}
75
​
76
@objc func WebViewError(_ notification: Notification){
77
print("Web View Error Recorded")
78
performSegue(withIdentifier: "InternetError", sender: nil)
79
}
80
​
81
}
82
​
83
​
84
​
Copied!
24. Add values to the places marked in the comments.
25. PayloadApi variable contains the user's payload.
26. Once the SAWO SDK is successfully set up, a login form will be rendered in the provided container as displayed in the picture below:
Final Render of SAWO Login
Congratulations !! The SAWO API is now ready to be used in your iOS application 🀘.

You can also check out SAWO's iOS Sample Code.

It's okay, we get it! You got Stuck!
😞
Feel free to contact us on #ask-for-help on our Discord​

Last modified 2mo ago