Thanks for pointing out these issues, I have modified my snippet according to your suggestion:
struct MobileProvision: Codable {
static let current: MobileProvision = {
guard
let profilePath = Bundle.main.url(
forResource: "embedded", withExtension: "mobileprovision"
),
let profileData = try? Data(contentsOf: profilePath),
let statrtRange = profileData.firstRange(
of: "<plist".data(using: .isoLatin1)!
),
let endRange = profileData.range(
of: "</plist>".data(using: .isoLatin1)!,
in: statrtRange.endIndex..<profileData.endIndex
)
else { return .`default`() }
let decoder = PropertyListDecoder()
do {
let plist = profileData.subdata(
in: statrtRange.startIndex..<endRange.endIndex
)
return try decoder.decode(MobileProvision.self, from: plist)
} catch {
return .`default`()
}
}()
static func `default`() -> Self {
#if targetEnvironment(simulator)
return Self(entitlements: Entitlements(isDebuggable: true, apsEnvironment: .development))
#else
return Self(entitlements: Entitlements(isDebuggable: false, apsEnvironment: .production))
#endif
}
let entitlements: Entitlements
enum CodingKeys: String, CodingKey {
case entitlements = "Entitlements"
}
struct Entitlements: Codable {
let isDebuggable: Bool
let apsEnvironment: APSEnvironment
enum APSEnvironment: String, Codable {
case development, production
}
enum CodingKeys: String, CodingKey {
case isDebuggable = "get-task-allow"
case apsEnvironment = "aps-environment"
}
}
}
Topic:
Developer Tools & Services
SubTopic:
General
Tags: