2016-10-28 52 views

回答

1

我建議設立兩個模式。

第一個:開發 - >設置與Debug構建配置。 您可以在開發應用時使用此功能。這會給你日誌記錄,調試容易等。

第二個:配置 - >設置與Release構建配置。 日誌記錄不會發生在這個模式上,調試也將不可用,因爲構建沒有爲此優化。

當您準備向App Store提交資料時,請使用Release構建配置來歸檔Distribution模式。

有關DebugRelease構建配置之間的區別的更多詳細說明here

+0

如果你是指打印()日誌記錄,將在發佈發生還建立,如果你不積極鎮壓。 – shallowThought

0

這將深入探討您的問題。我使用了構建配置環境,以便在發佈配置中進行構建。您的自動值將根據發佈版本進行調整。您還可以從下面的鏈接下載示例代碼,以實際瞭解更改方案時會發生什麼情況。

第一步。

在info.plist中添加變量「Configuration」,並在其中添加值「$(CONFIGURATION)」。

製作一個Config.swift文件並複製粘貼下面的代碼。

`

import Foundation 
private let configManagerSharedInstance = ConfigManager() 
class Config { 
    class var sharedInstance: ConfigManager { 
     return configManagerSharedInstance 
    } 
} 
// You can put as much Environment as you need but you make sure you also put these environment in the config.plist file. 
enum Environment: String { 
    case Debug = "Debug" 
    case Production = "Release" 
} 
class ConfigManager: NSObject { 
    private var environment: Environment? 
    var config: NSDictionary? 
    override init() { 
     super.init() 
     // Retrieve the current evironment from the main bundle 
     if let currentEnvironment = Bundle.main.infoDictionary?["Configuration"] as? String { 
      // Store the current environment for later use 
      environment = Environment(rawValue: currentEnvironment) 

      if let projectConfigPath = Bundle.main.path(forResource: "Config", ofType: "plist") { 
       if let projectConfigContents = NSDictionary(contentsOfFile: projectConfigPath) as? Dictionary<String, AnyObject> { 
        config = projectConfigContents[currentEnvironment] as? Dictionary<String, AnyObject> as NSDictionary? 
       } 
      } else { 
       print("config file not found") 
      } 
     } 
    } 
    func getCurrentEnvironment() -> Environment? { 
     return self.environment 
    } 
    func configForKey(key: String) -> String { 
     return config?[key] as! String 
    } 
    //It will use to get sub dictionary and their values. 
    func configForCategory(category: String, andKey: String) -> String { 
     let configuration = config?.value(forKeyPath: category) as! NSDictionary 
     return configuration.value(forKeyPath: andKey) as! String 
    } 
} 

`

我也取得了文件Constants.swift在我所使用上述代碼設定的可變因素。 `

 // 
    // Constants.swift 
    // BuildConfiguration 
    // 
    // Created by Ourangzaib khan on 4/6/17. 
    // Copyright © 2017 Ourangzaib khan. All rights reserved. 
    // 

    let kBASE_URL : String = { 
     print(Config.sharedInstance.configForKey(key: "kBASE_URL")); 
     return Config.sharedInstance.configForKey(key: "kBASE_URL") 
    }() 
    let STRIPEKEY : String = { 
     return Config.sharedInstance.configForCategory(category: "Stripe", andKey: "Publishable Key") 
    }() 

    let PUBNUBKEYSUBSCRIBE : String = { 
     return Config.sharedInstance.configForCategory(category: "PubNub", andKey: "Publish Key") 
    }() 

    let PUBNUBKEYPUBLISH : String = { 
     return Config.sharedInstance.configForCategory(category: "PubNub", andKey: "Subscribe Key") 
    }() 

let WOWZAKEY : String = { 
    return Config.sharedInstance.configForKey(key: "Wowza"); 
}() 

`

現在你只需要使用編輯sceme進入編輯方案來選擇環境和選擇構建配置現在,當你運行該項目,你會看到這樣的輸出WRT在下面的圖像中構建配置。

https://github.com/ourangzeb/Build-Configuration-for-IOS

相關問題