Man*_*tín 24 api parsing ios swift apple-watch
您好我正在尝试在GitHub中发布iOS(SWIFT)个人项目,但我害怕与所有人共享我的私有API密钥和秘密.
我正在使用解析,所以我在AppDelegate中有这样的东西:
let applicationId = "mySecretApplicationId"
let clientKey = "mySecretClientKey"
Parse.setApplicationId(applicationId!, clientKey: clientKey!)
Run Code Online (Sandbox Code Playgroud)
我想隐藏"mySecretApplicationId"和"mySecretClientKey",我的项目中是否有私有地方或目录,我可以放置这些变量?
谢谢!
Enr*_*iMR 31
您可以使用.plist
存储所有重要键的文件.将此文件放入您的.gitignore
文件非常重要.
在您的情况下,您需要keys.plist
像下面这样设置文件:
并在AppDelegate中使用它,如下所示:
var keys: NSDictionary?
if let path = NSBundle.mainBundle().pathForResource("Keys", ofType: "plist") {
keys = NSDictionary(contentsOfFile: path)
}
if let dict = keys {
let applicationId = dict["parseApplicationId"] as? String
let clientKey = dict["parseClientKey"] as? String
// Initialize Parse.
Parse.setApplicationId(applicationId!, clientKey: clientKey!)
}
Run Code Online (Sandbox Code Playgroud)
SWIFT 3更新:
if let path = Bundle.main.path(forResource: "Keys", ofType: "plist") {
keys = NSDictionary(contentsOfFile: path)
}
Run Code Online (Sandbox Code Playgroud)