0
我最近將我的應用程序從Parse Server遷移到我自己的自定義服務器。我試圖找到一種方法來訪問會話令牌,而無需在我的項目中導入Parse SDK。我需要會話令牌,所以我不必重新驗證當前登錄的用戶。直接在iOS上獲取分析服務器會話令牌Swift
到目前爲止,我用下面的方法訪問它,需要導入解析SDK:
PFUser.current()?.saveInBackground(block: { [weak self] (success, error) in
if let error = error {
Log.error?.message(error.localizedDescription)
return
}
guard let sessionToken = PFUser.current()?.sessionToken else {
Log.error?.message("Did not get session token even after saving user")
return
}
})
我看是解析的私人文件目錄中的其他解決辦法,但我只能得到的applicationID, installationId和配置從那裏:
class ParseHelper {
var parsePrivateDocumentsDirectory: URL? {
let filemanager = FileManager.default
guard let libraryDirectory = filemanager.urls(for: .libraryDirectory, in: .userDomainMask).last else {
return nil
}
guard let parseDirectory = URL(string: "Private%20Documents/Parse/", relativeTo: libraryDirectory) else {
return nil
}
return parseDirectory
}
func parseFile(_ filename: String) -> URL? {
let filemanager = FileManager.default
guard let parseDirectory = self.parsePrivateDocumentsDirectory else {
return nil
}
guard let installationIdUrl = URL(string: filename, relativeTo: parseDirectory) else {
return nil
}
if filemanager.fileExists(atPath: installationIdUrl.path) {
return installationIdUrl
} else {
return nil
}
}
var installationId: String? {
guard let fileURL = self.parseFile("installationId"), let data = try? Data(contentsOf: fileURL) else {
return nil
}
let string = String(data: data, encoding: String.Encoding.utf8)
return string
}
var applicationId: String? {
guard let fileURL = self.parseFile("applicationId"), let data = try? Data(contentsOf: fileURL) else {
return nil
}
let string = String(data: data, encoding: String.Encoding.utf8)
return string
}
var config: String? {
guard let fileURL = self.parseFile("config"), let data = try? Data(contentsOf: fileURL) else {
return nil
}
let string = String(data: data, encoding: String.Encoding.utf8)
return string
}
}