Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rkawajiri/1a0b01c2423ef7f0e0ed to your computer and use it in GitHub Desktop.
Save rkawajiri/1a0b01c2423ef7f0e0ed to your computer and use it in GitHub Desktop.
Detect if you're currently running a development version or an App Store/Ad Hoc version (Re-implemented in Swift)
public struct ProvisioningProfile {
public static let sharedInstance = ProvisioningProfile()
#if (arch(i386) || arch(x86_64)) && os(iOS)
public let isDevelopment = true
#else
public let isDevelopment: Bool
private init() {
guard let provision = NSBundle.mainBundle().pathForResource("embedded", ofType: "mobileprovision"),
let data = NSData(contentsOfFile: provision) else {
isDevelopment = false
return
}
let bytes = Array<UInt8>(UnsafeBufferPointer(start: UnsafePointer<UInt8>(data.bytes), count: data.length))
let profile = bytes
.map { UnicodeScalar($0) }
.filter { $0.isASCII() }
.reduce("") { "\($0)\($1)" }
.componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
.joinWithSeparator("")
isDevelopment = profile.rangeOfString("<key>get-task-allow</key><true/>")?.count > 0
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment