ios 如何链接到应用商店中的应用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/433907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to link to apps on the app store
提问by matt
I am creating a free version of my iPhone game. I want to have a button inside the free version that takes people to the paid version in the app store. If I use a standard link
我正在创建我的 iPhone 游戏的免费版本。我想在免费版本中有一个按钮,可以将人们带到应用商店中的付费版本。如果我使用标准链接
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300136119&mt=8
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300136119&mt=8
the iPhone opens Safari first, and then the app store. I have used other apps that open the app store directly, so I know it is possible.
iPhone 首先打开 Safari,然后打开应用商店。我用过其他直接打开应用商店的应用,所以我知道这是可能的。
Any ideas? What is the URL Scheme for the app store?
有任何想法吗?应用商店的 URL Scheme 是什么?
回答by Nathan S.
Edited on 2016-02-02
编辑于 2016-02-02
Starting from iOS 6 SKStoreProductViewControllerclass was introduced. You can link an app without leaving your app. Code snippet in Swift 3.x/2.xand Objective-Cis here.
从 iOS 6 开始引入了SKStoreProductViewController类。您无需离开应用程序即可链接应用程序。代码片断在斯威夫特3.X / 2.X和Objective-C的就是这里。
A SKStoreProductViewControllerobject presents a store that allows the user to purchase other media from the App Store. For example, your app might display the store to allow the user to purchase another app.
一个SKStoreProductViewController对象提出了一个商店,允许用户从App Store购买其他媒体。例如,您的应用可能会显示商店以允许用户购买另一个应用。
From News and Announcement For Apple Developers.
Drive Customers Directly to Your App on the App Store with iTunes Links With iTunes links you can provide your customers with an easy way to access your apps on the App Store directly from your website or marketing campaigns. Creating an iTunes link is simple and can be made to direct customers to either a single app, all your apps, or to a specific app with your company name specified.
To send customers to a specific application: http://itunes.com/apps/appname
To send customers to a list of apps you have on the App Store: http://itunes.com/apps/developername
To send customers to a specific app with your company name included in the URL: http://itunes.com/apps/developername/appname
使用 iTunes 链接将客户直接吸引到 App Store 上的应用程序 通过 iTunes 链接,您可以为客户提供一种直接从您的网站或营销活动访问 App Store 上的应用程序的简便方法。创建 iTunes 链接很简单,可以将客户引导至单个应用程序、您的所有应用程序或指定了您公司名称的特定应用程序。
将客户发送到特定应用程序:http: //itunes.com/apps/appname
将客户发送到您在 App Store 上拥有的应用程序列表:http: //itunes.com/apps/developername
将客户发送到 URL 中包含您的公司名称的特定应用程序:http: //itunes.com/apps/developername/appname
Additional notes:
补充说明:
You can replace http://
with itms://
or itms-apps://
to avoid redirects.
您可以替换http://
为itms://
或itms-apps://
以避免重定向。
Please notethat itms://
will send the user to the iTunes storeand itms-apps://
with send them to the App Store!
请注意,这itms://
会将用户发送到iTunes 商店并将itms-apps://
其发送到App Store!
For info on naming, see Apple QA1633:
有关命名的信息,请参阅 Apple QA1633:
https://developer.apple.com/library/content/qa/qa1633/_index.html.
https://developer.apple.com/library/content/qa/qa1633/_index.html。
Edit (as of January 2015):
编辑(截至 2015 年 1 月):
itunes.com/apps links should be updated to appstore.com/apps. See QA1633 above, which has been updated. A new QA1629suggests these steps and code for launching the store from an app:
itunes.com/apps 链接应更新为 appstore.com/apps。请参阅上面的 QA1633,已更新。新的QA1629建议了从应用程序启动商店的这些步骤和代码:
- Launch iTunes on your computer.
- Search for the item you want to link to.
- Right-click or control-click on the item's name in iTunes, then choose "Copy iTunes Store URL" from the pop-up menu.
- In your application, create an
NSURL
object with the copied iTunes URL, then pass this object toUIApplication
' sopenURL
: method to open your item in the App Store.
- 在您的计算机上启动 iTunes。
- 搜索您要链接到的项目。
- 在 iTunes 中右键单击或按住 Control 键单击项目的名称,然后从弹出菜单中选择“复制 iTunes Store URL”。
- 在您的应用程序中,
NSURL
使用复制的 iTunes URL创建一个对象,然后将此对象传递给UIApplication
的openURL
: 方法以在 App Store 中打开您的项目。
Sample code:
示例代码:
NSString *iTunesLink = @"itms://itunes.apple.com/app/apple-store/id375380948?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
Swift 4.2
斯威夫特 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)!)
}
回答by GeneCode
If you want to open an app directly to the App Store, you should use:
如果您想直接在 App Store 中打开应用程序,您应该使用:
itms-apps://...
itms-apps://...
This way it will directly open the App Store app in the device, instead of going to iTunes first, then only open the App Store (when using just itms://)
这样它会直接在设备中打开App Store应用程序,而不是先去iTunes,然后才打开App Store(当只使用itms://时)
Hope that helps.
希望有帮助。
EDIT: APR, 2017. itms-apps:// actually works again in iOS10. I tested it.
编辑:2017 年 4 月。 itms-apps:// 实际上在 iOS10 中再次起作用。我测试了它。
EDIT: APR, 2013. This no longer works in iOS5 and above. Just use
编辑:2013 年 4 月。这不再适用于 iOS5 及更高版本。只需使用
https://itunes.apple.com/app/id378458261
and there are no more redirects.
并且不再有重定向。
回答by Ramis
Starting from iOS 6 right way to do it by using SKStoreProductViewControllerclass.
从 iOS 6 开始,使用SKStoreProductViewController类正确地做到这一点。
Swift 5.x:
斯威夫特 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:
斯威夫特 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")
You can get the app's itunes item identifier like this: (instead of a static one)
您可以像这样获取应用程序的 iTunes 项目标识符:(而不是静态的)
Swift 3.2
斯威夫特 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:
斯威夫特 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:
目标-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];
}
You can get
kAppITunesItemIdentifier
(app's itunes item identifier) like this: (instead of a static one)
您可以
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]];
回答by Fattie
For summer 2015 onwards ...
从 2015 年夏季开始......
-(IBAction)clickedUpdate
{
NSString *simple = @"itms-apps://itunes.apple.com/app/id1234567890";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:simple]];
}
replace 'id1234567890' with 'id' and 'your ten digit number'
将“id1234567890”替换为“id”和“您的十位数字”
This works perfectly on all devices.
It does go straight tothe app store, no redirects.
Is OK for all national stores.
It's true you should move to using
loadProductWithParameters
, butif the purpose of the link is to update the app you are actually inside of: it's possibly better to use this "old-fashioned" approach.
这适用于所有设备。
它确实直接进入应用商店,没有重定向。
所有全国商店都可以。
的确,您应该转向 using
loadProductWithParameters
,但如果链接的目的是更新您实际所在的应用程序:使用这种“老式”方法可能会更好。
回答by Dev01
Apple just announced the appstore.com urls.
Apple 刚刚公布了 appstore.com 网址。
https://developer.apple.com/library/ios/qa/qa1633/_index.html
https://developer.apple.com/library/ios/qa/qa1633/_index.html
There are three types of App Store Short Links, in two forms, one for iOS apps, another for Mac Apps:
Company Name
iOS: http://appstore.com/for example, http://appstore.com/apple
Mac: http://appstore.com/mac/for example, http://appstore.com/mac/apple
App Name
iOS: http://appstore.com/for example, http://appstore.com/keynote
Mac: http://appstore.com/mac/for example, http://appstore.com/mac/keynote
App by Company
iOS: http://appstore.com// for example, http://appstore.com/apple/keynote
Mac: http://appstore.com/mac// for example, http://appstore.com/mac/apple/keynote
Most companies and apps have a canonical App Store Short Link. This canonical URL is created by changing or removing certain characters (many of which are illegal or have special meaning in a URL (for example, "&")).
To create an App Store Short Link, apply the following rules to your company or app name:
Remove all whitespace
Convert all characters to lower-case
Remove all copyright (?), trademark (?) and registered mark (?) symbols
Replace ampersands ("&") with "and"
Remove most punctuation (See Listing 2 for the set)
Replace accented and other "decorated" characters (ü, ?, etc.) with their elemental character (u, a, etc.)
Leave all other characters as-is.
Listing 2 Punctuation characters that must be removed.
!?"#$%'()*+,-./:;<=>??@[]^_`{|}~
Below are some examples to demonstrate the conversion that takes place.
App Store
Company Name examples
Gameloft => http://appstore.com/gameloft
Activision Publishing, Inc. => http://appstore.com/activisionpublishinginc
Chen's Photography & Software => http://appstore.com/chensphotographyandsoftware
App Name examples
Ocarina => http://appstore.com/ocarina
Where's My Perry? => http://appstore.com/wheresmyperry
Brain Challenge? => http://appstore.com/brainchallenge
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 中具有特殊含义(例如,“&”))来创建的。
要创建 App Store 短链接,请将以下规则应用于您的公司或应用程序名称:
删除所有空格
将所有字符转换为小写
删除所有版权 (?)、商标 (?) 和注册商标 (?) 符号
用“and”替换和号(“&”)
删除大部分标点符号(请参阅清单 2 了解该集)
将重音和其他“修饰”字符(ü、? 等)替换为其元素字符(u、a 等)
保留所有其他字符。
清单 2 必须删除的标点符号。
!?"#$%'()*+,-./:;<=>??@[]^_`{|}~
下面是一些示例来演示发生的转换。
应用商店
公司名称示例
Gameloft => http://appstore.com/gameloft
动视出版公司 => http://appstore.com/activisionpublishinginc
陈的摄影和软件 => http://appstore.com/chensphotographyandsoftware
应用名称示例
陶笛 => http://appstore.com/ocarina
我的佩里在哪里?=> http://appstore.com/wheresmyperry
回答by Tibidabo
This code generates the App Store link on iOS
此代码在 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:@""]]];
Replace itms-apps with http on Mac:
在 Mac 上用 http 替换 itms-apps:
NSURL *appStoreURL = [NSURL URLWithString:[NSString stringWithFormat:@"http:/itunes.com/app/%@",[appName stringByReplacingOccurrencesOfString:@" " withString:@""]]];
Open URL on iOS:
在 iOS 上打开网址:
[[UIApplication sharedApplication] openURL:appStoreURL];
Mac:
苹果电脑:
[[NSWorkspace sharedWorkspace] openURL:appStoreURL];
回答by dulgan
To have a direct link without redirection :
有一个没有重定向的直接链接:
- Use iTunes link maker http://itunes.apple.com/linkmaker/to get the real direct link
- Replace the
http://
withitms-apps://
- Open the link with
[[UIApplication sharedApplication] openURL:url];
- 使用 iTunes 链接制作器http://itunes.apple.com/linkmaker/获取真正的直接链接
- 更换
http://
用itms-apps://
- 打开链接
[[UIApplication sharedApplication] openURL:url];
Be careful, those links only works on actual devices, not in simulator.
请注意,这些链接仅适用于实际设备,不适用于模拟器。
Source : https://developer.apple.com/library/ios/#qa/qa2008/qa1629.html
来源:https: //developer.apple.com/library/ios/#qa/qa2008/qa1629.html
回答by matt
Simply change 'itunes' to 'phobos' in the app link.
只需在应用程序链接中将“itunes”更改为“phobos”即可。
http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300136119&mt=8
http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300136119&mt=8
Now it will open the App Store directly
现在它会直接打开App Store
回答by Almas Adilbek
This worked for me perfectly using only APP ID:
仅使用 APP ID 这对我来说非常有效:
NSString *urlString = [NSString stringWithFormat:@"http://itunes.apple.com/app/id%@",YOUR_APP_ID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
The number of redirects is ZERO.
重定向次数为零。
回答by Ben Flynn
A number of answers suggest using 'itms' or 'itms-apps' but this practice is not specifically recommended by Apple. They only offer the following way to open the App Store:
许多答案建议使用“itms”或“itms-apps”,但 Apple 并未特别推荐这种做法。他们只提供以下打开 App Store 的方式:
Listing 1Launching the App Store from an iOS application
清单 1从 iOS 应用程序启动 App Store
NSString *iTunesLink = @"https://itunes.apple.com/us/app/apple-store/id375380948?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
See https://developer.apple.com/library/ios/qa/qa1629/_index.htmllast updated March, 2014 as of this answer.
请参阅https://developer.apple.com/library/ios/qa/qa1629/_index.html最后更新于 2014 年 3 月,截至本答案。
For apps that support iOS 6 and above, Apple offers a in-app mechanism for presenting the App Store: SKStoreProductViewController
对于支持 iOS 6 及更高版本的应用程序,Apple 提供了一种应用程序内机制来呈现 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
}];
Note that on iOS6, the completion block may not be called if there are errors. This appears to be a bug that was resolved in iOS 7.
请注意,在 iOS6 上,如果出现错误,可能不会调用完成块。这似乎是在 iOS 7 中解决的错误。