我正在创造自己的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方案是什么?
当前回答
如果你有应用商店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);
}
其他回答
当支持多个操作系统和平台时,创建链接可能会成为一个复杂的问题。例如,在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的示例项目。
只需在应用程序链接中将“itunes”改为“phobos”即可。
http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300136119&mt=8
现在它会直接打开应用商店
试试这个方法
http://itunes.apple.com/lookup?id=“你的应用ID在这里”返回json。从这里,找到键“trackViewUrl”和值是所需的url。使用这个url(只需将https://替换为itms-apps://)。这工作得很好。
例如,如果你的应用ID是xyz,那么就转到这个链接 http://itunes.apple.com/lookup?id=xyz
然后找到“trackViewUrl”键的url。这是你的应用程序在应用商店的url,在xcode中使用这个url试试这个
NSString *iTunesLink = @"itms-apps://itunes.apple.com/us/app/Your app name/id Your app ID?mt=8&uo=4";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
谢谢
如果你想链接到开发商的应用,而开发商的名字中有标点符号或空格(例如Development Company, LLC),你的URL是这样的:
itms-apps://itunes.com/apps/DevelopmentCompanyLLC
否则它在iOS 4.3.3上返回“此请求不能被处理”
至少iOS 9及以上版本
直接在App Store打开
一个应用程序
itms-apps://itunes.apple.com/app/[appName]/[appID]
开发者的应用程序列表
itms-apps://itunes.apple.com/developer/[developerName]/[developerID]