Skip to content

Commit

Permalink
- Hashable & init?()
Browse files Browse the repository at this point in the history
- Fix decode failed when apns not config.
  • Loading branch information
CrazyFanFan committed Sep 21, 2022
1 parent 32df7c1 commit cc49c62
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion K3MobileProvision.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "K3MobileProvision"
spec.version = "0.0.3"
spec.version = "0.0.4"
spec.summary = "A tool to decode *mobileprovision* plist file."

spec.description = <<-DESC
Expand Down
10 changes: 5 additions & 5 deletions Sources/MobileProvision/Entitlements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public extension MobileProvision.Entitlements.InAppIdentityPresentment.Key {
}

public extension MobileProvision {
enum Environment: String, Decodable {
enum Environment: String, Decodable, Hashable {
case development
case production
case disabled
}

// Sublevel: decode entitlements informations
struct Entitlements: Decodable {
struct Entitlements: Decodable, Hashable {
public var applicationIdentifier: String?

// MARK: - Topic: Authentication
Expand Down Expand Up @@ -199,7 +199,7 @@ public extension MobileProvision {
// MARK: - Topic: Push Notifications

/// The environment for push notifications.
public var apsEnvironment: Environment
public var apsEnvironment: Environment?

/// The environment for push notifications in macOS apps.
public var developerApsEnvironment: String?
Expand Down Expand Up @@ -355,7 +355,7 @@ public extension MobileProvision {

// MARK: - Topic: Sensors

public enum Sensors: String, Decodable {
public enum Sensors: String, Decodable, Hashable {
/// A sensor that describes the watch’s position on the wrist.
case onWrist = "on-wrist"

Expand Down Expand Up @@ -504,7 +504,7 @@ public extension MobileProvision {
public enum InAppIdentityPresentment {
public typealias Key = String

public enum Value: String, Codable {
public enum Value: String, Codable, Hashable {
case usDriversLicense = "us-drivers-license"

case givenName = "given-name"
Expand Down
44 changes: 27 additions & 17 deletions Sources/MobileProvision/MobileProvision.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@

import Foundation

public struct MobileProvision: Decodable {
public var appIDName: String
public var applicationIdentifierPrefix: [String]
public var creationDate: Date
public var platform: [String]
public var isXcodeManaged: Bool? = false
public var developerCertificates: [Data]
public var entitlements: Entitlements
public var expirationDate: Date
public var name: String
public var provisionedDevices: [String]?
public var teamIdentifier: [String]
public var teamName: String
public var timeToLive: Int
public var uuid: String
public var version: Int
public struct MobileProvision: Decodable, Hashable {
public private(set) var appIDName: String
public private(set) var applicationIdentifierPrefix: [String]
public private(set) var creationDate: Date
public private(set) var platform: [String]
public private(set) var isXcodeManaged: Bool? = false
public private(set) var developerCertificates: [Data]
public private(set) var entitlements: Entitlements
public private(set) var expirationDate: Date
public private(set) var name: String
public private(set) var provisionedDevices: [String]?
public private(set) var teamIdentifier: [String]
public private(set) var teamName: String
public private(set) var timeToLive: Int
public private(set) var uuid: String
public private(set) var version: Int

public private(set) var path: URL!

private enum CodingKeys: String, CodingKey {
case appIDName = "AppIDName"
Expand All @@ -41,6 +43,11 @@ public struct MobileProvision: Decodable {
case uuid = "UUID"
case version = "Version"
}

public init?(with fileURL: URL) {
guard let value = Self.read(from: fileURL.path) else { return nil }
self = value
}
}

public extension MobileProvision {
Expand Down Expand Up @@ -86,7 +93,10 @@ public extension MobileProvision {
let decoder = PropertyListDecoder()

do {
return try decoder.decode(MobileProvision.self, from: plist)
var provision = try decoder.decode(MobileProvision.self, from: plist)
provision.path = URL(fileURLWithPath: path)

return provision
} catch {
print(error)
return nil
Expand Down

0 comments on commit cc49c62

Please sign in to comment.