Created
February 2, 2023 02:57
-
-
Save iHTCboy/cc61cb1ec2349f535a760a346fd6d6ca to your computer and use it in GitHub Desktop.
检测 iOS App 是否 TestFlight 下载的 ipa
This file contains 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
OC | |
``` | |
if ([[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"]) { | |
// TestFlight | |
} else { | |
// App Store (and Apple reviewers too) | |
} | |
BOOL isRunningTestFlightBeta = [[[[NSBundle mainBundle] appStoreReceiptURL] lastPathComponent] isEqualToString:@"sandboxReceipt"]; | |
``` | |
Swift | |
``` | |
/// 是否是 testflight包 | |
public static var isTestFlight: Bool { | |
return isAppStoreReceiptSandbox && !hasEmbeddedMobileProvision | |
} | |
/// 是否是 Appstore 包 | |
public static var isAppStore: Bool { | |
if isAppStoreReceiptSandbox || hasEmbeddedMobileProvision { | |
return false | |
} | |
return true | |
} | |
fileprivate static var isAppStoreReceiptSandbox: Bool { | |
let b = Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt" | |
NSLog("isAppStoreReceiptSandbox: \(b)") | |
return b | |
} | |
fileprivate static var hasEmbeddedMobileProvision: Bool { | |
let b = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") != nil | |
NSLog("hasEmbeddedMobileProvision: \(b)") | |
return b | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment