SDKを使用してアプリケーションを実行する前に、いくつかのステップを実行する必要があります:
インターフェイスクラスの作成
ViewController クラスの作成: UIViewController
ViewController.Swiftの作成
import UIKit
import SafousWaap
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// MARK: transaction
SafousWaap.shared.transaction (
onSuccess: {
response in
print(response)
},
onError: {
error in
print(error)
}
)
}
}
レスポンスモデルの作成
ViewController2.mの作成
#import < Foundation / Foundation.h >
#import "ViewController2.h"
@import SafousWaap;
@interface ViewController2()
@end
@implementation ViewController2
-
(void) viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// MARK: Transaction
SafousWaap * safousWaap = [
[SafousWaap alloc] init
];
[safousWaap transactionOnSuccess: ^ (NSString * result) {
NSLog(@ "%@", result);
}
onError: ^ (NSString * error) {
NSLog(@ "%@", error);
}
];
シンプルなコードでの作業について
以下のコードを追加してください。詳細については、コード中にコメントを追加しています。
// SafousWaapExample
// AppDelegate.swift
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow ?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any] ? ) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let vc = storyboard.instantiateViewController(withIdentifier: "ViewController2") as ? ViewController2 {
window?.rootViewController = vc
}
window?.makeKeyAndVisible()
return true
}
}
// SafousWaapExample/SafousWaap.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>X-AppId</key>
<string>c3395dcc-c41a-4076-bee9-87a331048f32</string>
<key>CertificateName</key>
<string>device.xxxx.xxxx.safous.com/</string>
<key>CertificatePassword</key>
<string>Safous123</string>
<key>BaseUrl</key>
<dict>
<key>Device</key>
<string>https://device.xxxx.xxxx.safous.com</string>
<key>Auth</key>
<string>https://auth.xxxx.xxxx.safous.com</string>
<key>VerifyToken</key>
<string>https://device.xxxx.xxxx.safous.com/</string>
</dict>
</dict>
</plist>
//for example ViewController.swift
// SafourAuthExample
import UIKit
import SafousWaap
//Setup envi & mobile init xcframwork
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
SafousWaap.shared.transaction(
//mobile hit api Back End with function sdk
onSuccess: {
// onSuccess: Success response with payload
response in
guard
var urlRequest = response,
let url = URL(string: "www.example.com")
// url: Full url
else {
return
}
urlRequest.url = url
urlRequest.setValue("Real Date XXXX", forHTTPHeaderField: "Date")
// headers: Headers (optional)
urlRequest.setValue("Authorization XXXXX", forHTTPHeaderField: "Authorization")
// headers: Headers (optional)
urlRequest.httpMethod = "GET"
// method: .get or .post
URLSession.shared.dataTask(with: urlRequest, completionHandler: {
// this is for handling response
(data, response, error) in
})
},
onError: {
error in
print(error)
}
)
}
}