Forked from steipete/DevelopmentEnviromentDetector.m
Last active
May 30, 2017 14:15
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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