iOS iTunes store country - iphone

i am wondering if there is a solution to find out, in which country the user downloaded an application.
For example: app x has been downloaded in USA when the user opens up the app, the app will check in which country it was downloaded. In this example the the return would be "USA"
Does any one hase an idea on how to solve this?

If you have any In-App Purchases available, you can read the locale from the SKProduct. As a fallback, use the device's locale.
NSLocale *locale;
SKProduct *baseProduct = nil; // replace as applicable
if (baseProduct) {
locale = baseProduct.priceLocale; // from the user's credit card on iTunes
} else {
locale = [NSLocale currentLocale]; // from user preferences
}
NSString *countryCode = [locale objectForKey:NSLocaleCountryCode];
NSLog(#"Two-letter country code: %#", countryCode);

There might be a good enough correlation between the iTunes store country and the locale a user sets. This depends on your needs - if this does not suffice, I don't think there is a way to know which actual store an app was downloaded from.
To retrieve that locale, you could use:
NSString *localeIdentifier = [[NSLocale currentLocale] localeIdentifier];
Hope this is sufficient for your needs.

It's not possible to check "which" App Store an app was downloaded.
If you need to do anything location-based, you should look at CLLocation to obtain a user's current location, however it may seem intrusive for the app to ask a user for their location if it's not apparent why it would need the location.
You could also check for the language on a users device, such as en_gb for Britain, dk for Denmark, en_ca for Canada, etc. While this doesn't completely cover when people in some countries have set the language to something else than the countries native language, it's better than nothing.

SKStoreFront, introduced in iOS 13 SDK seems to do the job.
Swift
if let storefront = SKPaymentQueue.default().storefront {
print(storefront.countryCode) // Returns an Alpha-3 country code (USA, GBR etc.)
}
Obj C
[SKPaymentQueue defaultQueue].storefront.countryCode; // Returns an Alpha-3 country code (USA, GBR etc.)
You should be able to access the SKStoreFront instance by adding the StoreKit framework to your project, even if your app does not offer any purchases.

Related

Detect country of iTunes Store in iOS [duplicate]

This question already has answers here:
How to detect the active iTunes store on the iPhone/iPod Touch/iPad?
(7 answers)
Closed 8 years ago.
In my iPhone app I would like to detect the country of iTunes Store the iPhone user is logged into, e.g. for a user from USA I would like to direct him/her to:
https://itunes.apple.com/us/album/21/id420075073
and for a user who is logged into the Polish iTunes Store I would like to redirect him to:
https://itunes.apple.com/us/album/21/id403037872
I know that I could check the locale (e.g. the language),but it might not always work.
Any ideas how to achieve this?
NSString *countryCode = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode];
will get you an identifier like e.g. "US" (United States), "ES" (Spain), etc.
Because you find country means no problem. We hope the iTunes store must be Device country.

Currency Conversion and display fetched from Server

I am fetching the in app purchase items for my app from my web server.the web-server gives the product title, description and price...
Currently i am displaying the each product using the product title,description and price.Currently i am showing the currency in $.
Now i am having the doubt that , can i display the prices as such?when i referred some URL, it seems that prices needs to be localized.
So do i need to display the prices localized which is fetched from my-server? please let me know how should i proceed?
Thanks a lot for stopping by..
Yes, you should show localized prices.
From App Store Quick Reference: Getting Started with In-App Purchase on iOS and OS X Lion:
Since your application may be available in App Stores with a region specific currency and
language, your item’s localized description and pricing information should be pulled from the
App Store via StoreKit’s products request API. You’ll use the information returned from the
products request to populate the user interface you present to the customer for item selection
and purchase
The product request API from StoreKit is pretty straightforward, it returns a ProductResponse, which contains an SKProduct, which includes both the price and the priceLocale. Per the SKProduct Class Reference, your code to format the price in the current local should be something like:
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:product.priceLocale];
NSString *formattedString = [numberFormatter stringFromNumber:product.price];

iTunes Music Store Link Maker — how to search from within my app?

I'm writing a music reference app and for each album (pulled from last.fm) would like to link to the ITMS (if the album is in the store).
iTunes link maker web tool http://apple.com/itunes/linkmaker/ is great for getting links for a known album but I need to access it programatically from within my app.
This NSLog blogpost which is from 2003 but was referenced more recently in another question here seems to offer the only solution I've come across so far, suggesting to submit a query to:
phobos.apple.com/WebObjects/MZSearch.woa/wa/advancedSearchResults?
Put "itms://" before it and the link will work in iTunes, put "http://" before it and the link will work in Camino (Safari sometimes spits back a malformed XML error).
The tags that are of importance are as follows:
songTerm - song title
artistTerm - artist name
albumTerm - album name
composerTerm - composer name
term - all fields
The suggestion is that would using http:// rather than itms:// the server will return an XML document of results instead of opening iTunes but either way I am sent directly to iTunes.
Is it possible to get back a list of results?
I am using LinkMaker to get iTunes details about song I am playing.
For that, I found that LinkMaker is able to return json data and also 1 result at a time.
I am using this url to perfom my query :
http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/itmsSearch?lang=1&output=json&country=%#&term=%#&media=%#&limit=1"
Here are parameters you need to give :
> country : store country term : could
> contains artist name, song name, album
> media : music
For exemple, if you want to have details for a song called "One" by "U2" here is the correct URL :
http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/itmsSearch?lang=1&output=json&country=US&term=U2%20one&media=music&limit=1
Then you will receive json data like this :
{
"resultCount":1,
"results": [
{"wrapperType":"track", "mediaType":"song", "artistName":"U2", "itemParentName":"Achtung Baby", "itemParentCensoredName":"Achtung Baby", "itemCensoredName":"One", "itemName":"One", "artistLinkUrl":"http://itunes.apple.com/us/artist/u2/id78500?uo=4", "artworkUrl60":"http://a1.phobos.apple.com/us/r1000/009/Features/32/9a/60/dj.mfynlttx.60x60-50.jpg", "artworkUrl100":"http://a1.phobos.apple.com/us/r1000/009/Features/32/9a/60/dj.mfynlttx.100x100-75.jpg", "country":"USA", "currency":"USD", "discCount":1, "discNumber":1, "itemExplicitness":"notExplicit", "itemLinkUrl":"http://itunes.apple.com/us/album/one/id368713?i=368617&uo=4", "itemPrice":"1.29000", "itemParentExplicitness":"notExplicit", "itemParentLinkUrl":"http://itunes.apple.com/us/album/one/id368713?i=368617&uo=4", "itemParentPrice":"9.99000", "previewUrl":"http://a1.phobos.apple.com/us/r1000/019/Music/b6/8c/c5/mzm.epegonxg.aac.p.m4a", "primaryGenreName":"Rock", "trackCount":12, "trackNumber":3, "trackTime":276042}]
}
You need then to decode these JSON data.
NSDictionary *jsonResultsParsed = [jsonResults JSONValue];
And finally get what you want :
NSDictionary *songDetailsDict = [[jsonResultsParsed objectForKey:#"results"] objectAtIndex:0];
If you want to determine user's country you will need to determine its country using its locale, here is the code I am using :
- (NSString *)getUserCountry
{
NSLocale *locale = [NSLocale currentLocale];
return [locale objectForKey: NSLocaleCountryCode];
}
Hope this helps.
Thierry
Edit: Finally a doc is available:
http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html
This document for iTunes Store Web Service Search API (pdf), although old and incomplete, seems to be the way to accomplish this.
It's a painful experience setting this up though, as has been every other part of the affiliate programme.

Is there any API to find MCC for iPhone? [duplicate]

As per the subject - is there an API to get the MCC/MNC on iPhone OS 2.1 or above?
Added in iOS4
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
NSString *mcc = [carrier mobileCountryCode];
NSString *mnc = [carrier mobileNetworkCode];
http://developer.apple.com/library/ios/#Documentation/NetworkingInternet/Reference/CTCarrier/Reference/Reference.html
No, mobile network information is not available through the API. If you're looking for a unique device ID, take a look at UIDevice's uniqueIdentifer method; if you're looking for the country the device is in, you need Location Services; if you want a good indication of the user's home region, take a look at NSLocale; for anything else, just ask the user.
I think you could just get the phone number of the iPhone and parse it out for the country code.

iPhone: Beta Features of Facebook Connect

I have an iPhone app idea that will include viewing your news feed( stream ) in an iPhone app. There is a lot more to it than that, but I'm wondering why I can't find any apps on the app store that lets you view your stream in some way. Does anyone know why?
Does facebook frown on this? There is a API method stream.get that lets you do this but it's in beta. Is it a bad idea to use the beta methods in an app?
I'm just suprised that there is so many different twitter clients but there is just on facebook client and why hasn't created streams in an iPhone app besides the main facebook app?
I have implemented what you are talking about and my app is in the App Store, albeit only in a couple European stores currently. It was, however, reviewed and approved in the US App Store. I can't send a link for it currently as we are not yet announcing it in the US (until December), however, I assure you it can be done and is not too hard to implement.
I don't think Facebook frowns upon this so much as I think their API just hasn't matured enough yet. It's getting there, though. I think mostly what you see (or don't see in the App Store) is from a lack of vision for how to use Facebook for applications. The official Facebook app provides what users need but ideas like yours are going to grow as more and more people (developers/entrepreneurs) realize that Facebook is not just a social network, but an entire social networking platform they can leverage in a powerful way... Ok. I've said too much. Cool stuff is coming in December, though. ;-)
If you don't want to use the beta features, you can go for FQL to get what you want. Here is the code I used to implement pulling the last 20 friend status updates:
NSString* fql = [NSString stringWithFormat:
#"SELECT uid, pic_square, name, status FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = %lld) AND status.time > 0 ORDER BY status.time DESC LIMIT 20", fbSession.uid];
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:#"query"];
last20FriendsStatusRequest = [FBRequest requestWithDelegate:self];
[last20FriendsStatusRequest call:#"facebook.fql.query" params:params];
And then the delegate callback looks like this:
- (void)request:(FBRequest*)request didLoad:(id)result
{
if (request == last20FriendsStatusRequest)
{
// Callback to my delegate here. result is an NSArray*
// of NSDictionaries* containing key-value pairs for the
// fields you requested in the query, e.g. uid, pic_square,
// name, and status. pic_square is the URL of the user's
// profile picture icon.
}
}
Let me know if you need any more info.
I guess people haven't found a use for it. Other developers may be afraid of the beta tag (yes Facebook, unlike Google, treats it as a beta tag -- it's subject to change and may break your app). It's up to your judgement if you think it's "safe" enough. We're currently developing a commercial iPhone application that uses stream.get.
On the desktop there are multiple apps that user Stream.get(), which could as well be done on iPhone