Showing App's Build Date

后端 未结 6 941
情书的邮戳
情书的邮戳 2021-02-04 05:23

I am able to display the build date for my app in the simulator, but whenever I archive the app, and upload it to TestFlight, and then install it on a device, the build date doe

6条回答
  •  無奈伤痛
    2021-02-04 05:46

    Swift3

    static var buildDate: Date? {
        guard let infoPath = Bundle.main.path(forResource: "Info.plist", ofType: nil) else {
            return nil
        }
        guard let infoAttr = try? FileManager.default.attributesOfItem(atPath: infoPath) else {
            return nil
        }
        let key = FileAttributeKey(rawValue: "NSFileCreationDate")
        guard let infoDate = infoAttr[key] as? Date else {
            return nil
        }
        return infoDate
    }
    
    static var prettyBuildDate: String {
        guard let date = buildDate else {
            return "Unknown"
        }
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss ZZZ"
        formatter.timeZone = TimeZone(abbreviation: "UTC")
        return formatter.string(from: date)
    }
    

提交回复
热议问题