Is there any way for getting appstore id from running iOS application? (For asking user to rate it and providing link to appstore.)
You can use this below function. Note: This API is not documented in Apple.
//MARK: To get app iTunes id and app name
func getAppDetailsFromServer() {
var bundleIdentifier: String {
return Bundle.main.infoDictionary?["CFBundleIdentifier"] as! String
}
let baseURL: String = "http://itunes.apple.com/lookup?bundleId=\(bundleIdentifier)"
let encodedURL = baseURL.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)
// Creating URL Object
let url = URL(string:encodedURL!)
// Creating a Mutable Request
var request = URLRequest.init(url: url!)
//Setting HTTP values
request.httpMethod = "GET"
request.timeoutInterval = 120
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration)
let downloadTask = session.dataTask(with: request, completionHandler: { (data, response, error) -> Void in
//API Call over,getting Main queue
DispatchQueue.main.async(execute: { () -> Void in
if error == nil
{
if data != nil {
do {
let resultDictionary:NSDictionary! = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! NSDictionary
if resultDictionary != nil && resultDictionary.count > 0 {
if (resultDictionary.object(forKey: "results") as! NSArray).count != 0 {
let AppName = "\(((resultDictionary.object(forKey: "results") as! NSArray).object(at: 0) as! NSDictionary).object(forKey: "trackCensoredName")!)"
let AppId = "\(((resultDictionary.object(forKey: "results") as! NSArray).object(at: 0) as! NSDictionary).object(forKey: "trackId")!)"
print("AppName : \(AppName) \nAppId: \(AppId)")
}
} else {
print("Unable to proceed your request,Please try again")
}
} catch {
print("Unable to proceed your request,Please try again")
}
} else {
print("Unable to proceed your request,Please try again")
}
} else {
print("Unable to proceed your request,Please try again")
}
})
})
downloadTask.resume()
}
You can use the Apple iTunes Link Maker to search for your App (or any app for that matter) and get your App Store URL. From there you could get your App URL which will remain the same for your App and put it in your Application. When you use itms:// instead of http://, it will directly open in the App Store app directly
For example, if I wanted to use the Twitter App URL, the link maker tells me the URL is:
http://itunes.apple.com/us/app/twitter/id333903271?mt=8&uo=4
Now do the itms trick:
itms://itunes.apple.com/us/app/twitter/id333903271?mt=8&uo=4
And it will directly open in the App Store than redirect via Safari then to the App Store,
Yes, it is. You can't get appstore app id (called Apple ID in iTunes Connect) offline, but you can request it using iTunes Search Api. Download the context of the following link:
http://itunes.apple.com/lookup?bundleId=YOUR_APP_BUNDLE_ID
You will get a JSON response, containing "trackId":YOUR_APP_ID
key-value. Try it in your browser!
My answer is based on the another answer: https://stackoverflow.com/a/11626157/3050403
Use
NSString* appID = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
Updating the answer with comment by @zaheer
NSBundle.mainBundle().infoDictionary?["CFBundleIdentifier"] as? NSString
get the app id like this
guard let bundleID = Bundle.main.infoDictionary?["CFBundleIdentifier"] as? String else {
return
}
let url = "https://itunes.apple.com/lookup?bundleId=\(bundleID)"
Alamofire.request(url).responseJSON { response in
guard let value = response.result.value else { return }
let json = JSON(value) // from: import SwiftyJSON
let storeVersion = json["results"][0]["version"].stringValue
let storeProductID = json["results"][0]["trackId"].intValue
// result: 1506562619
}
For the appId only you need to separate the bundle identifier string by components and simply grab the last component.
NSString appId = [[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"] componentsSeparatedByString:@"."] lastObject];
Or handle the full string accordingly but it will have the entire bundle identifier.