[英]How Can I Launch The Appstore App Directly from my Application
I've used several apps now that launch the itunes store directly from the app. 我现在使用了几个应用程序直接从应用程序启动itunes商店。 I'm even using some on my 2.1 iPod 2G.
我甚至在2.1 iPod 2G上使用了一些。
I know there's a bug in 2.1 that prevents appstore links from working in safari, but somehow people are launching the appstore directly, not even through safari. 我知道2.1中有一个错误阻止appstore链接在safari中工作,但不知何故人们直接启动appstore,甚至没有通过safari启动。
How do you do this? 你怎么做到这一点? Is it an undocumented openURL feature?
它是一个未记录的openURL功能吗?
To be extremely concise: 要非常简洁:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/appname"]];
If you want to send to all the apps for a developer, use 如果要发送给开发人员的所有应用程序,请使用
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/developername"]];
These work for iOS 4.1 这些适用于iOS 4.1
See Also How to link to apps on the app store 另请参阅如何链接到应用商店中的应用
From iTunes, drag the icon of your app to the desktop, this will give you a link you can use directly (for example, 在iTunes中,将应用程序的图标拖到桌面上,这将为您提供可以直接使用的链接(例如, http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284036524&mt=8 launches the AppStore to Crosswords, both on a desktop and an iPhone).
http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284036524&mt=8在桌面和iPhone上启动AppStore到Crosswords。
Pop this into an NSURL and call openURL on it. 将其弹出到NSURL并在其上调用openURL。
I figured out how to get straight into the review page for an app in the AppStore. 我想出了如何直接进入AppStore中应用程序的评论页面。
Basically it's done like below, feel free to read my blog post about it. 基本上它完成如下,随时阅读我的博客文章 。
- (IBAction)gotoReviews:(id)sender
{
NSString *str = @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa";
str = [NSString stringWithFormat:@"%@/wa/viewContentsUserReviews?", str];
str = [NSString stringWithFormat:@"%@type=Purple+Software&id=", str];
// Here is the app id from itunesconnect
str = [NSString stringWithFormat:@"%@289382458", str];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
If you want to show the details of the application instead of the reviews, you can use the url like this: 如果要显示应用程序的详细信息而不是评论,可以使用以下URL:
NSString *appId = @"app id";
NSString *endPoint = [NSString stringWithFormat:@"phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@&mt=8", appId];
NSString *link = [NSString stringWithFormat:@"itms-apps://%@", endPoint];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:link]];
I've tested this on my iPhone with iOS 6.1 and will redirect you to the App Store app immediately. 我已经在iOS 6.1上使用iOS 6.1对其进行了测试,并会立即将您重定向到App Store应用程序。
Ben Gottlieb is right, but there's a faster way to get the URL: You can right-click on any application icon in iTunes and select "Copy iTunes Store URL". Ben Gottlieb是对的,但有更快的方法来获取URL:您可以右键单击iTunes中的任何应用程序图标,然后选择“复制iTunes Store URL”。
Then call UIApplication openURL
on it. 然后在其上调用
UIApplication openURL
。
您可以从itunesconnect.apple.com“管理您的应用程序”获取您的AppID
Make sure it says "phobos.apple.com" and not "itunes.apple.com" 确保它显示“phobos.apple.com”而不是“itunes.apple.com”
The former opens the App Store directly, while the latter will open MobileSafari first, then the App Store. 前者直接打开App Store,后者首先打开MobileSafari,然后打开App Store。
If you do not want to get the link for iTunes you can do this. 如果您不想获取iTunes的链接,可以执行此操作。
I have had this work at time the iTunes link would not. 我有这个工作,iTunes链接不会。
Here is the code I use and tested it against the various iOS versions mentioned. 这是我使用的代码,并针对上面提到的各种iOS版本进行了测试。 Obviously change the customer id to be your one:
显然,将客户ID更改为您的客户ID:
- (void)showOurAppsInAppStore
{
NSString *searchUrl = nil;
// iPad
if ([DeviceController isDeviceAnIpad]) {
searchUrl = @"itms-apps://itunes.apple.com/us/artist/seligman-ventures-ltd/id326161338";
}
// iPhone / iPod Touch
else {
// iOS 7+
if ([DeviceController isDeviceOperatingSystemAtleast:@"7.0"]) {
searchUrl = @"itms-apps://itunes.apple.com/artist/seligman-ventures-ltd/id326161338";
}
// iOS 6
else if ([DeviceController isDeviceOperatingSystemAtleast:@"6.0"]) {
searchUrl = @"itms-apps://ax.itunes.apple.com/artist/seligman-ventures-ltd/id326161338";
}
// Pre iOS 6
else {
NSString *companyName = @"Seligman Ventures";
searchUrl = [NSString stringWithFormat:@"http://phobos.apple.com/WebObjects/MZSearch.woa/wa/search?WOURLEncoding=ISO8859_1&lang=1&output=lm&country=US&term=%@&media=software", [companyName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}
}
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:searchUrl]];
}
If you have an affiliate link and you would like to still open App Store app directly without Safari in the middle, you could use a hidden UIWebView or an NSURLConnection. 如果您有联盟链接,并且您仍希望在没有Safari的情况下直接打开App Store应用程序,则可以使用隐藏的UIWebView或NSURLConnection。 For the latter see this post http://gamesfromwithin.com/handling-app-store-and-linkshare-links
对于后者,请参阅此文章http://gamesfromwithin.com/handling-app-store-and-linkshare-links
If you are just releasing your app... you won't have an "app ID #" yet... so none of those methods will work. 如果你刚刚发布你的应用程序...你还没有“应用程序ID#”......所以这些方法都不会起作用。
I had to insert a "non-working link" in my v1.0... and then later in my v1.1 update... added the actual link and app ID #. 我不得不在我的v1.0中插入一个“非工作链接”...然后在我的v1.1更新中...添加了实际链接和应用程序ID#。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.