我正在创造自己的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方案是什么?
当前回答
这是工作和直接链接在ios5
NSString *iTunesLink = @"http://itunes.apple.com/app/baseball-stats-tracker-touch/id490256272?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
其他回答
你可以通过以下链接生成器获得应用商店或iTunes中特定项目的链接: http://itunes.apple.com/linkmaker/
这对我来说非常有效,只使用APP ID:
NSString *urlString = [NSString stringWithFormat:@"http://itunes.apple.com/app/id%@",YOUR_APP_ID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
重定向的数量为0。
许多答案建议使用“itms”或“itms-apps”,但苹果并没有特别推荐这种做法。他们只提供以下方式打开App Store:
清单1从iOS应用程序启动App Store
NSString *iTunesLink = @"https://itunes.apple.com/us/app/apple-store/id375380948?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
参见https://developer.apple.com/library/ios/qa/qa1629/_index.html, 2014年3月更新。
对于支持iOS 6及以上版本的应用程序,苹果提供了一种应用内机制来呈现应用程序商店: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上,如果有错误,completion块可能不会被调用。这似乎是一个在iOS 7中解决的错误。
我可以确认,如果你在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];
工作是一种享受
如果你有应用商店id,你最好使用它。特别是当您将来可能更改应用程序的名称时。
http://itunes.apple.com/app/id378458261
如果你没有应用商店id,你可以根据这个文档创建一个url https://developer.apple.com/library/ios/qa/qa1633/_index.html
+ (NSURL *)appStoreURL
{
static NSURL *appStoreURL;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
appStoreURL = [self appStoreURLFromBundleName:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]];
});
return appStoreURL;
}
+ (NSURL *)appStoreURLFromBundleName:(NSString *)bundleName
{
NSURL *appStoreURL = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.com/app/%@", [self sanitizeAppStoreResourceSpecifier:bundleName]]];
return appStoreURL;
}
+ (NSString *)sanitizeAppStoreResourceSpecifier:(NSString *)resourceSpecifier
{
/*
https://developer.apple.com/library/ios/qa/qa1633/_index.html
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.
*/
resourceSpecifier = [resourceSpecifier stringByReplacingOccurrencesOfString:@"&" withString:@"and"];
resourceSpecifier = [[NSString alloc] initWithData:[resourceSpecifier dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES] encoding:NSASCIIStringEncoding];
resourceSpecifier = [resourceSpecifier stringByReplacingOccurrencesOfString:@"[!¡\"#$%'()*+,-./:;<=>¿?@\\[\\]\\^_`{|}~\\s\\t\\n]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, resourceSpecifier.length)];
resourceSpecifier = [resourceSpecifier lowercaseString];
return resourceSpecifier;
}
通过测试
- (void)testAppStoreURLFromBundleName
{
STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"Nuclear™"].absoluteString, @"itms-apps://itunes.com/app/nuclear", nil);
STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"Magazine+"].absoluteString, @"itms-apps://itunes.com/app/magazine", nil);
STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"Karl & CO"].absoluteString, @"itms-apps://itunes.com/app/karlandco", nil);
STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"[Fluppy fuck]"].absoluteString, @"itms-apps://itunes.com/app/fluppyfuck", nil);
STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"Pollos Hérmanos"].absoluteString, @"itms-apps://itunes.com/app/polloshermanos", nil);
STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"Niños and niñas"].absoluteString, @"itms-apps://itunes.com/app/ninosandninas", nil);
STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"Trond, MobizMag"].absoluteString, @"itms-apps://itunes.com/app/trondmobizmag", nil);
STAssertEqualObjects([AGApplicationHelper appStoreURLFromBundleName:@"!__SPECIAL-PLIZES__!"].absoluteString, @"itms-apps://itunes.com/app/specialplizes", nil);
}