Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
76 lines (58 sloc) 1.88 KB
//
// UIApplicationExtensions.swift
// SwifterSwift
//
// Created by Omar Albeik on 3/30/19.
// Copyright © 2019 SwifterSwift
//
#if canImport(UIKit)
import UIKit
#if os(iOS) || os(tvOS)
public extension UIApplication {
/// SwifterSwift: Application running environment.
///
/// - debug: Application is running in debug mode.
/// - testFlight: Application is installed from Test Flight.
/// - appStore: Application is installed from the App Store.
enum Environment {
case debug
case testFlight
case appStore
}
/// SwifterSwift: Current inferred app environment.
var inferredEnvironment: Environment {
#if DEBUG
return .debug
#elseif targetEnvironment(simulator)
return .debug
#else
if Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") != nil {
return .testFlight
}
guard let appStoreReceiptUrl = Bundle.main.appStoreReceiptURL else {
return .debug
}
if appStoreReceiptUrl.lastPathComponent.lowercased() == "sandboxreceipt" {
return .testFlight
}
if appStoreReceiptUrl.path.lowercased().contains("simulator") {
return .debug
}
return .appStore
#endif
}
/// SwifterSwift: Application name (if applicable).
var displayName: String? {
return Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String
}
/// SwifterSwift: App current build number (if applicable).
var buildNumber: String? {
return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String
}
/// SwifterSwift: App's current version number (if applicable).
var version: String? {
return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
}
}
#endif
#endif
You can’t perform that action at this time.