我正在制作我的iPhone游戏的免费版本。我想在免费版本中放置一个按钮,可以将人们带到应用商店中的付费版本。如果我使用标准链接
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300136119&mt=8
iPhone首先会打开Safari,然后再进入应用商店。我已经使用过其他应用程序,它们可以直接打开应用商店,所以我知道这是可能的。
有什么想法吗?应用商店的URL Scheme是什么?
我正在制作我的iPhone游戏的免费版本。我想在免费版本中放置一个按钮,可以将人们带到应用商店中的付费版本。如果我使用标准链接
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300136119&mt=8
iPhone首先会打开Safari,然后再进入应用商店。我已经使用过其他应用程序,它们可以直接打开应用商店,所以我知道这是可能的。
有什么想法吗?应用商店的URL Scheme是什么?
编辑于2016-02-02
iOS 6开始引入SKStoreProductViewController类,应用内打开App Store页面。在Swift 3.x/2.x和Objective-C中的代码示例在这里。
SKStoreProductViewController对象呈现一个商店,允许用户从App Store购买其他媒体。例如,您的应用程序可能显示商店以让用户购买另一个应用程序。
使用iTunes链接直接将客户带到App Store上的应用程序,您可以通过iTunes链接为客户提供直接从您的网站或营销活动访问您的应用程序的简单方法。创建iTunes链接很简单,可以设置为将客户定向到单个应用程序、所有应用程序或指定公司名称的特定应用程序。
要将客户发送到特定的应用程序:
http://itunes.com/apps/appname要将客户发送到您在App Store上有的应用程序列表:
http://itunes.com/apps/developername要将客户发送到包含您公司名称的特定应用程序中,请使用以下URL:
http://itunes.com/apps/developername/appname
额外说明:
您可以将http://
替换为itms://
或itms-apps://
以避免重定向。
请注意,itms://
会将用户发送到iTunes商店,而itms-apps://
将他们发送到App Store!
有关命名的信息,请参见Apple QA1633:
https://developer.apple.com/library/content/qa/qa1633/_index.html。
编辑(截至2015年1月):
itunes.com/apps链接应更新为appstore.com/apps。请参见已更新的QA1633。新的QA1629建议使用以下步骤和代码从应用程序启动商店:
NSURL
对象,然后将此对象传递给UIApplication
的openURL
:方法,以在App Store中打开您的项目。示例代码:
NSString *iTunesLink = @"itms://itunes.apple.com/app/apple-store/id375380948?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
iOS10+:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink] options:@{} completionHandler:nil];
Swift 4.2
let urlStr = "itms-apps://itunes.apple.com/app/apple-store/id375380948?mt=8"
if #available(iOS 10.0, *) {
UIApplication.shared.open(URL(string: urlStr)!, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(URL(string: urlStr)!)
}
appname
应该使用哪个正确的值?是应用程序的“Bundle Display Name”吗?它是否不区分大小写?空格如何处理等等? - aroth如果你想直接打开应用程序的App Store页面,你应该使用:
itms-apps://...
这样它将直接在设备中打开App Store应用程序,而不是首先进入iTunes,再仅打开App Store(当只使用itms://时)
编辑:2017年4月。itms-apps://在iOS10中实际上又起作用了。我进行了测试。
编辑:2013年4月。这在iOS5及以上版本中不再起作用。只需使用
https://itunes.apple.com/app/id378458261
并且没有更多的重定向。
itms-apps
通过 openURL:
在 iOS 10.2 中为我打开 App Store 应用程序。看起来没有问题。 - pkambiOS 6以后,使用SKStoreProductViewController类是正确的方法。
Swift 5.x:
func openStoreProductWithiTunesItemIdentifier(_ identifier: String) {
let storeViewController = SKStoreProductViewController()
storeViewController.delegate = self
let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier]
storeViewController.loadProduct(withParameters: parameters) { [weak self] (loaded, error) -> Void in
if loaded {
// Parent class of self is UIViewContorller
self?.present(storeViewController, animated: true, completion: nil)
}
}
}
private func productViewControllerDidFinish(viewController: SKStoreProductViewController) {
viewController.dismiss(animated: true, completion: nil)
}
// Usage:
openStoreProductWithiTunesItemIdentifier("1234567")
Swift 3.x:
func openStoreProductWithiTunesItemIdentifier(identifier: String) {
let storeViewController = SKStoreProductViewController()
storeViewController.delegate = self
let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier]
storeViewController.loadProduct(withParameters: parameters) { [weak self] (loaded, error) -> Void in
if loaded {
// Parent class of self is UIViewContorller
self?.present(storeViewController, animated: true, completion: nil)
}
}
}
func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
viewController.dismiss(animated: true, completion: nil)
}
// Usage:
openStoreProductWithiTunesItemIdentifier(identifier: "13432")
你可以这样获取应用程序的iTunes项目标识符:(而不是静态的)
Swift 3.2
var appID: String = infoDictionary["CFBundleIdentifier"]
var url = URL(string: "http://itunes.apple.com/lookup?bundleId=\(appID)")
var data = Data(contentsOf: url!)
var lookup = try? JSONSerialization.jsonObject(with: data!, options: []) as? [AnyHashable: Any]
var appITunesItemIdentifier = lookup["results"][0]["trackId"] as? String
openStoreProductViewController(withITunesItemIdentifier: Int(appITunesItemIdentifier!) ?? 0)
Swift 2.x:
func openStoreProductWithiTunesItemIdentifier(identifier: String) {
let storeViewController = SKStoreProductViewController()
storeViewController.delegate = self
let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier]
storeViewController.loadProductWithParameters(parameters) { [weak self] (loaded, error) -> Void in
if loaded {
// Parent class of self is UIViewContorller
self?.presentViewController(storeViewController, animated: true, completion: nil)
}
}
}
func productViewControllerDidFinish(viewController: SKStoreProductViewController) {
viewController.dismissViewControllerAnimated(true, completion: nil)
}
// Usage
openStoreProductWithiTunesItemIdentifier("2321354")
Objective-C:static NSInteger const kAppITunesItemIdentifier = 324684580;
[self openStoreProductViewControllerWithITunesItemIdentifier:kAppITunesItemIdentifier];
- (void)openStoreProductViewControllerWithITunesItemIdentifier:(NSInteger)iTunesItemIdentifier {
SKStoreProductViewController *storeViewController = [[SKStoreProductViewController alloc] init];
storeViewController.delegate = self;
NSNumber *identifier = [NSNumber numberWithInteger:iTunesItemIdentifier];
NSDictionary *parameters = @{ SKStoreProductParameterITunesItemIdentifier:identifier };
UIViewController *viewController = self.window.rootViewController;
[storeViewController loadProductWithParameters:parameters
completionBlock:^(BOOL result, NSError *error) {
if (result)
[viewController presentViewController:storeViewController
animated:YES
completion:nil];
else NSLog(@"SKStoreProductViewController: %@", error);
}];
[storeViewController release];
}
#pragma mark - SKStoreProductViewControllerDelegate
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
[viewController dismissViewControllerAnimated:YES completion:nil];
}
您可以像这样获取kAppITunesItemIdentifier
(应用程序的iTunes项标识符):(而不是静态的)NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString* appID = infoDictionary[@"CFBundleIdentifier"];
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appID]];
NSData* data = [NSData dataWithContentsOfURL:url];
NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSString * appITunesItemIdentifier = lookup[@"results"][0][@"trackId"];
[self openStoreProductViewControllerWithITunesItemIdentifier:[appITunesItemIdentifier intValue]];
苹果刚刚宣布了appstore.com网址。
https://developer.apple.com/library/ios/qa/qa1633/_index.html
有三种类型的App Store短链接,分别是两种形式,一种用于iOS应用程序,另一种用于Mac应用程序:
公司名称
iOS:http://appstore.com/ 例如,http://appstore.com/apple
Mac:http://appstore.com/mac/ 例如,http://appstore.com/mac/apple
应用程序名称
iOS:http://appstore.com/ 例如,http://appstore.com/keynote
Mac:http://appstore.com/mac/ 例如,http://appstore.com/mac/keynote
公司的应用程序
iOS:http://appstore.com// 例如,http://appstore.com/apple/keynote
Mac: http://appstore.com/mac// 例如,http://appstore.com/mac/apple/keynote
大多数公司和应用程序都有一个规范的App Store简短链接。这个规范的URL是通过更改或删除某些字符(其中许多是非法的或在URL中具有特殊含义的字符(例如,“&”))创建的。
删除所有空格
将所有字符转换为小写
删除所有版权(©)、商标(™)和注册标志(®)符号
用“and”替换“&”
删除大部分标点符号(请参见清单2中的集合)
用其元素字符(u、a等)替换重音和其他“装饰”字符(ü,å等)
保留所有其他字符不变。
清单2必须删除的标点符号。
!¡"#$%'()*+,-./:;<=>¿?@[]^_`{|}~
以下是一些示例,以演示进行的转换。
Gameloft => http://appstore.com/gameloft
Activision Publishing, Inc. => http://appstore.com/activisionpublishinginc
陈氏摄影与软件 => http://appstore.com/chensphotographyandsoftware
Ocarina => http://appstore.com/ocarina
Where’s My Perry? => http://appstore.com/wheresmyperry
Brain Challenge™ => http://appstore.com/brainchallenge
-(IBAction)clickedUpdate
{
NSString *simple = @"itms-apps://itunes.apple.com/app/id1234567890";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:simple]];
}
用'id'和你的十位数替换'id1234567890'
在所有设备上都能完美运行。
它会直接进入应用商店,没有重定向。
对于所有国家商店都可以。
确实应该转而使用 loadProductWithParameters
,但是如果链接的目的是要更新你当前所在的应用程序:可能更好地使用这种“老式”的方法。
如何获取直接链接而无需重定向:
https://
替换为 itms-apps://
。UIApplication.shared.open(url, options: [:])
打开链接。请注意,这些链接仅适用于实际设备,而不适用于模拟器。
来源:
https://tools.applemediaservices.com/app-store/
。 - rwcorbett这段代码在iOS上生成App Store链接
NSString *appName = [NSString stringWithString:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]];
NSURL *appStoreURL = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.com/app/%@",[appName stringByReplacingOccurrencesOfString:@" " withString:@""]]];
在 Mac 上将 itms-apps 替换为 http:
NSURL *appStoreURL = [NSURL URLWithString:[NSString stringWithFormat:@"http:/itunes.com/app/%@",[appName stringByReplacingOccurrencesOfString:@" " withString:@""]]];
iOS中打开URL:
[[UIApplication sharedApplication] openURL:appStoreURL];
苹果电脑:
[[NSWorkspace sharedWorkspace] openURL:appStoreURL];
只需将应用程序链接中的 'itunes' 更改为 'phobos'。
http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300136119&mt=8
现在它会直接打开App Store。
只使用应用程序ID,这个方法完美地适用于我:
NSString *urlString = [NSString stringWithFormat:@"http://itunes.apple.com/app/id%@",YOUR_APP_ID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
重定向次数为零。
许多答案建议使用 'itms' 或 'itms-apps',但这种做法并没有得到苹果公司的特别推荐。他们只提供了以下打开应用商店的方式:
清单1 从iOS应用程序启动应用商店
NSString *iTunesLink = @"https://itunes.apple.com/us/app/apple-store/id375380948?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
请参考此答案发布日期为2014年3月的更新内容:https://developer.apple.com/library/ios/qa/qa1629/_index.html
对于支持iOS 6及以上版本的应用程序,苹果提供了一个内置机制来展示App Store:SKStoreProductViewController
- (void)loadProductWithParameters:(NSDictionary *)parameters completionBlock:(void (^)(BOOL result, NSError *error))block;
// Example:
SKStoreProductViewController* spvc = [[SKStoreProductViewController alloc] init];
spvc.delegate = self;
[spvc loadProductWithParameters:@{ SKStoreProductParameterITunesItemIdentifier : @(364709193) } completionBlock:^(BOOL result, NSError *error){
if (error)
// Show sorry
else
// Present spvc
}];
请注意,在iOS6上,如果出现错误,可能不会调用完成块。这似乎是iOS 7中解决的一个错误。