我正在创造自己的iPhone游戏的免费版本。我想在免费版本中添加一个按钮,引导用户进入应用商店中的付费版本。如果我使用标准链接
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300136119&mt=8
iPhone首先打开Safari,然后打开应用商店。我使用过其他直接打开应用程序商店的应用程序,所以我知道这是可能的。
什么好主意吗?应用商店的URL方案是什么?
我正在创造自己的iPhone游戏的免费版本。我想在免费版本中添加一个按钮,引导用户进入应用商店中的付费版本。如果我使用标准链接
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300136119&mt=8
iPhone首先打开Safari,然后打开应用商店。我使用过其他直接打开应用程序商店的应用程序,所以我知道这是可能的。
什么好主意吗?应用商店的URL方案是什么?
当前回答
当支持多个操作系统和平台时,创建链接可能会成为一个复杂的问题。例如,在iOS 7上不支持WebObjects(其中一些),你创建的一些链接会打开另一个国家的商店,然后用户的等等。
有一个叫做iLink的开源库可以帮助你。
There advantages of this library is that the links would be found and created at run time (the library would check the app ID and the OS it is running on and would figure out what link should be created). The best point in this is that you don't need to configure almost anything before using it so that is error free and would work always. That's great also if you have few targets on same project so you don't have to remember which app ID or link to use. This library also would prompt the user to upgrade the app if there is a new version on the store (this is built in and you turn this off by a simple flag) directly pointing to the upgrade page for the app if user agrees.
复制两个库文件到你的项目(iLink.h & iLink.m)。
在你的appDelegate.m上:
#import "iLink.h"
+ (void)initialize
{
//configure iLink
[iLink sharedInstance].globalPromptForUpdate = YES; // If you want iLink to prompt user to update when the app is old.
}
例如,在你想打开评级页面的地方,只需使用:
[[iLink sharedInstance] iLinkOpenAppPageInAppStoreWithAppleID: YOUR_PAID_APP_APPLE_ID]; // You should find YOUR_PAID_APP_APPLE_ID from iTunes Connect
不要忘记在同一个文件中导入iLink.h。
这里有一个很好的整个库的文档还有一个iPhone和Mac的示例项目。
其他回答
2015年夏天开始……
-(IBAction)clickedUpdate
{
NSString *simple = @"itms-apps://itunes.apple.com/app/id1234567890";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:simple]];
}
将'id1234567890'替换为'id'和'您的十位数'
这在所有设备上都能完美地工作。 它会直接进入应用商店,没有重定向。 对全国所有商店都是可以的。 的确,你应该转而使用loadProductWithParameters,但如果链接的目的是更新你实际所在的应用程序:使用这种“老式”方法可能更好。
这段代码生成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上用http替换itms-apps:
NSURL *appStoreURL = [NSURL URLWithString:[NSString stringWithFormat:@"http:/itunes.com/app/%@",[appName stringByReplacingOccurrencesOfString:@" " withString:@""]]];
在iOS上打开URL:
[[UIApplication sharedApplication] openURL:appStoreURL];
Mac:
[[NSWorkspace sharedWorkspace] openURL:appStoreURL];
编辑于2016-02-02
从ios6开始,SKStoreProductViewController类被引入。你可以在不离开你的应用程序的情况下链接一个应用程序。x和Objective-C在这里。
SKStoreProductViewController对象表示一个存储,该存储允许 用户可以从应用商店购买其他媒体。例如,你的应用程序 可能会显示商店以允许用户购买另一款应用。
来自苹果开发者的新闻和公告。
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
其他说明:
为了避免重定向,可以将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建议从应用程序启动商店的步骤和代码:
在你的电脑上启动iTunes。 搜索要链接的项目。 在iTunes中右键单击或控制单击项目名称,然后从弹出菜单中选择“复制iTunes Store URL”。 在你的应用中,用复制的iTunes URL创建一个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];
斯威夫特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)!)
}
我可以确认,如果你在iTunes connect上创建应用,你会在提交应用之前获得应用id。
因此. .
itms-apps://itunes.apple.com/app/id123456789
NSURL *appStoreURL = [NSURL URLWithString:@"itms-apps://itunes.apple.com/app/id123456789"];
if ([[UIApplication sharedApplication]canOpenURL:appStoreURL])
[[UIApplication sharedApplication]openURL:appStoreURL];
工作是一种享受
如果你想链接到开发商的应用,而开发商的名字中有标点符号或空格(例如Development Company, LLC),你的URL是这样的:
itms-apps://itunes.com/apps/DevelopmentCompanyLLC
否则它在iOS 4.3.3上返回“此请求不能被处理”