Check if iOS app is live in app store

ぃ、小莉子 提交于 2020-01-10 08:51:12

问题


Is it possible somehow to code like below in iOS app ?

if(app is live in app store)
{
   //Do something
}
else
{
  //Do other thing
}

I wanted to avoid cases where our QE/Dev team is using app for testing. Is there a way I can detect how app code is signed (Developer/Adhoc/Distribution) to check ? Even if it is possible, it will not eliminate cases when Apple is using our app for testing as part of review. We recorded many downloads of our content by Apple before our app goes live in App store.


回答1:


You can determine if your app was distributed via the app store by checking for the absence of embedded.mobileprovision. This file is only included in adhoc builds.

Like this:

if ([[NSBundle mainBundle] pathForResource:@"embedded"
                                    ofType:@"mobileprovision"]) {
  // not from app store (Apple's reviewers seem to hit this path)
} else {
  // from app store
}

This technique is from the HockeyApp SDK. I personally have applications in the store that use this technique, and of course there are many apps distributed that include the HockeyApp SDK.

Based on an immediate crash I accidentally released in a particular build of my application in the "from app store" path, Apple's team will follow the "not from app store" path. Let my loss be your gain on that one. :)




回答2:


On iOS 7 and later, you may also be able to check:

if ([NSData dataWithContentsOfURL:[NSBundle mainBundle].appStoreReceiptURL] != nil) {
    // Downloaded from App Store
} else {
    // Not downloaded from App Store
}



回答3:


This isn't working anymore with XCode 7, I would suggest to use the new HockeyApp workaround https://github.com/bitstadium/HockeySDK-iOS/blob/6b727733a5a93847b4a7ff8a734692dbe4e3a979/Classes/BITHockeyHelper.m Here is a simplified version:

+ (BOOL)isAppStoreBuild
{
#ifdef DEBUG
    return NO;
#else
    return ([UIApplication isTestFlightBuild] == NO);
#endif
}

+ (BOOL)isTestFlightBuild
{
#ifdef DEBUG
    return NO;
#else
    NSURL *appStoreReceiptURL = NSBundle.mainBundle.appStoreReceiptURL;
    NSString *appStoreReceiptLastComponent = appStoreReceiptURL.lastPathComponent;
    BOOL isSandboxReceipt = [appStoreReceiptLastComponent isEqualToString:@"sandboxReceipt"];

    return isSandboxReceipt;
#endif
}



回答4:


I faced a similar situation in my app. At least I think I did, I'm not sure I'm entirely understanding your question.

In my app I have users with accounts create content. I don't want developer content (or Apple employees content) from polluting the public content. I have a "test" bit in the user data structure that gets turned on and test content is not visible to the public. I've not submitted to the App Store yet but I'll need to work with Apple to make sure that their accounts have this test bit turned on.

If this isn't your goal, well, never mind then! :- )




回答5:


Swift

func isAppStoreBuild() -> Bool {

    if NSBundle.mainBundle().appStoreReceiptURL != nil {
        if let _ = NSData(contentsOfURL: NSBundle.mainBundle().appStoreReceiptURL!) {
            return true
        }
    }
    return false
}



回答6:


For the Swift version:

private static let isTestFlight = NSBundle.mainBundle().appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"

This complete answer explains more elaborately on how you could use it.



来源:https://stackoverflow.com/questions/9906504/check-if-ios-app-is-live-in-app-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!