2017-07-17 50 views
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 
    } 
} 

回答

1

的唯一文件Private Documents/Parse提供有:

  • 的applicationID
  • currentInstallation
  • currentUser
  • installationId

的sessionToken在另一方面,存儲在鑰匙串。
關鍵應該是$APP_BUNDLE_ID.com.parse.sdkOfficial infosource codehere's用於保存數據的函數的來源)。

如果您遇到任何問題,here's問題的官方回購關於服務器遷移和會話

相關問題