我正在创造自己的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方案是什么?
当前回答
在SwiftUI - IOS 15.0
//
// Test.swift
// PharmaCodex
//
import SwiftUI
struct Test: View {
var body: some View {
VStack {
Button(action: {
guard let writeReviewURL = URL(string: "https://apps.apple.com/app/id1629135515?action=write-review") else {
fatalError("Expected a valid URL")
}
UIApplication.shared.open(writeReviewURL, options: [:], completionHandler: nil)
}) {
Text("Rate/Review")
}
}
}
}
struct Test_Previews: PreviewProvider {
static var previews: some View {
Test()
}
}
其他回答
苹果刚刚公布了appstore.com的网址。
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
这段代码生成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];
这是重定向/链接应用商店中其他现有应用程序的简单而简短的方法。
NSString *customURL = @"http://itunes.apple.com/app/id951386316";
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customURL]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
}
在SwiftUI - IOS 15.0
//
// Test.swift
// PharmaCodex
//
import SwiftUI
struct Test: View {
var body: some View {
VStack {
Button(action: {
guard let writeReviewURL = URL(string: "https://apps.apple.com/app/id1629135515?action=write-review") else {
fatalError("Expected a valid URL")
}
UIApplication.shared.open(writeReviewURL, options: [:], completionHandler: nil)
}) {
Text("Rate/Review")
}
}
}
}
struct Test_Previews: PreviewProvider {
static var previews: some View {
Test()
}
}
这里的大多数解决方案都过时了
为那些寻找更新的工作解决方案
// let appStoreLink = "https://apps.apple.com/app/{app-name}/{app-id}"
guard let url = URL(string: Constants.App.appStoreLink) else { return }
UIApplication.shared.open(url)