How to detect the active iTunes store on the iPhone/iPod Touch/iPad?

前端 未结 7 765
你的背包
你的背包 2020-12-07 23:29

I\'d like to be able to determine which store the user connects to from inside my app, so that I can direct them to some appropriate content for their device AND store. Doe

7条回答
  •  孤街浪徒
    2020-12-07 23:39

    So far you can use 2 methods with their pros and cons:

    StoreFront

    ->SDK >= 13

    ->The three-letter code representing the country associated with the App Store storefront

    if let storeFront = SKPaymentQueue.default().storefront{
        print("StoreFront CountryCode = ", storeFront.countryCode)
    }
    else {
        print("StoreFront NOT Available")
    }
    

    OR

    SKCloudServiceController

    -> Available from iOS 9.3.

    -> Requires permission. On tvOS it can become messy as I can't find a way to change the permissions in settings...

    -> Permission text quite confusing.

    let skCloudServiceController = SKCloudServiceController()
    SKCloudServiceController.requestAuthorization { (status) in
        guard status == .authorized else {
            return
        }
    
        skCloudServiceController.requestStorefrontCountryCode(completionHandler: { (countryCode, error)  in
            if let error = error {
                print("Failure: ", error)
            }
                else if let countryCode = countryCode {
                print("Country code: ", countryCode)
            }
        })
    }
    

    Don't forget to include that in your .plist file:

    NSAppleMusicUsageDescription
    Store information
    

提交回复
热议问题