在這篇開始要使用 NCCommunication 跟 Webkit,還沒裝 NCCommunication 套件的同仁們請點擊這
首先
import NCCommunication
import WebKit
與 NextCloud 連線
func connectUrl( serverUrl : String ) {
NCCommunication.shared.getServerStatus(serverUrl: serverUrl) { (_ serverProductName: String?, _ serverVersion: String? , _ versionMajor: Int, _ versionMinor: Int, _ versionMicro: Int, _ extendedSupport: Bool, _ errorCode: Int, _ errorDescription: String) in
if errorCode == 0 {
print("success")
}else{
print("error")
}
}
}
getURL username password
func APIAction( serverUrl : String , username : String , password : String) {
//MARK: - getURL username password
NCCommunication.shared.getAppPassword(serverUrl: serverUrl, username: username, password: password) { (_ token : String?, _ errorCode : Int, _ errorDescription : String) in
}
}
在裡面打如果成功 errorcode = 0 ,就進行 login flow V2,若失敗就跳出提示框
if (errorCode == 0){
//MARK: - LoginFlowV2
NCCommunication.shared.getLoginFlowV2(serverUrl: serverUrl) { (_ token : String?,_ endpoint : String?,_ login: String?,_ errorCode : Int, _ errorDescription: String) in
self.loadURL(urlString: login!)
self.tokentest = token
self.endpointtest = endpoint
self.loginFlowV2Available = true
}
}else{
self.alertAction(title: "訊息", message: "輸入有誤")
DispatchQueue.main.asyncAfter(deadline: .now() + 2){
self.dismiss(animated: true, completion: nil)
}
}