How to detect that a provisioning profile is for development or distribution, programmatically

后端 未结 4 2123
庸人自扰
庸人自扰 2020-12-08 14:41

I would like to detect if a given provisioning profile is a development profile or a distribution (adhoc or app store) profile. I need to do this purely programmatically.

4条回答
  •  执笔经年
    2020-12-08 14:59

    Here is a version for Swift 3, based on @steipete's answer:

    static func isDevelopmentProvisioningProfile() -> Bool {
    #if IOS_SIMULATOR
        return true
    #else
        // there will be no provisioning profile in AppStore Apps
        guard let fileName = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") else {
            return false
        }
    
        let fileURL = URL(fileURLWithPath: fileName)
        // the documentation says this file is in UTF-8, but that failed
        // on my machine. ASCII encoding worked ¯\_(ツ)_/¯
        guard let data = try? String(contentsOf: fileURL, encoding: .ascii) else {
            return false
        }
    
        let cleared: String = data.components(separatedBy: .whitespacesAndNewlines).joined()
        return cleared.contains("get-task-allow")
    #endif
    }
    

    If curious, get-task-allow is a flag that the build uses to determine whether you should be able to hook up a debugger and other processes like that - so it's quite accurate for whether it is a dev build or no.

提交回复
热议问题