4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Provisioning profileがdevelopmentかdistributionをプログラムから判断

Last updated at Posted at 2016-02-27

Push Notificationなんかをするとき、現在のProvisioning profileがdevelopmentかdistributionかを知りたい時があります。
調べると直接とれるAPIは無いみたいで、以下のStack Overflowが出てきます。

上記のStackoverFlowをもとに、Objective-Cで実装したgistがありました。
https://gist.github.com/steipete/7668246

これを参考にSwiftで再実装しました。
https://gist.github.com/rkawajiri/1a0b01c2423ef7f0e0ed

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
}
4
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?