链接到应用名称中带有 "space" 的应用商店
Linking to app store with a "space" in app name
我想link从我的应用直接到应用商店。
我正在使用此代码:
var url = NSURL(string: "itms-apps://itunes.com/apps/companyname/appname")
if UIApplication.sharedApplication().canOpenURL(url!) == true {
UIApplication.sharedApplication().openURL(url!)
}
当应用程序名称中没有 space 时,它可以正常工作。但是应用程序名称中是否有一个 space,它不会 link 到应用程序本身,而是 link 到包含我所有应用程序的页面。怎么会?
示例:如果应用名称 = bobbie,我使用:
var url = NSURL(string: "itms-apps://itunes.com/apps/mycompany/bobbie")
if UIApplication.sharedApplication().canOpenURL(url!) == true {
UIApplication.sharedApplication().openURL(url!)
}
(完美运行)
但是它 app name = bob bie ,我使用:
var url = NSURL(string: "itms-apps://itunes.com/apps/mycompany/bob-bie")
if UIApplication.sharedApplication().canOpenURL(url!) == true {
UIApplication.sharedApplication().openURL(url!)
}
但这不会 link 应用...
为您的应用程序使用 iTunes 连接中提供的 link。
- 打开iTunes Connect
- 登录
- 点击"My apps"
- Select 你的应用程序
- 点击"More"
- 为"Show in App Store"
复制link
您只需使用 stringByAddingPercentEscapesUsingEncoding:
将 space 替换为 %20
let link = "itms-apps://itunes.com/apps/mycompany/bob bie"
if let linkWithPercentEscape = link.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) {
println(linkWithPercentEscape)
if let url = NSURL(string: linkWithPercentEscape) {
println(url)
if UIApplication.sharedApplication().canOpenURL(url) {
UIApplication.sharedApplication().openURL(url)
}
}
}
我想link从我的应用直接到应用商店。
我正在使用此代码:
var url = NSURL(string: "itms-apps://itunes.com/apps/companyname/appname")
if UIApplication.sharedApplication().canOpenURL(url!) == true {
UIApplication.sharedApplication().openURL(url!)
}
当应用程序名称中没有 space 时,它可以正常工作。但是应用程序名称中是否有一个 space,它不会 link 到应用程序本身,而是 link 到包含我所有应用程序的页面。怎么会?
示例:如果应用名称 = bobbie,我使用:
var url = NSURL(string: "itms-apps://itunes.com/apps/mycompany/bobbie")
if UIApplication.sharedApplication().canOpenURL(url!) == true {
UIApplication.sharedApplication().openURL(url!)
}
(完美运行)
但是它 app name = bob bie ,我使用:
var url = NSURL(string: "itms-apps://itunes.com/apps/mycompany/bob-bie")
if UIApplication.sharedApplication().canOpenURL(url!) == true {
UIApplication.sharedApplication().openURL(url!)
}
但这不会 link 应用...
为您的应用程序使用 iTunes 连接中提供的 link。
- 打开iTunes Connect
- 登录
- 点击"My apps"
- Select 你的应用程序
- 点击"More"
- 为"Show in App Store" 复制link
您只需使用 stringByAddingPercentEscapesUsingEncoding:
将 space 替换为 %20let link = "itms-apps://itunes.com/apps/mycompany/bob bie"
if let linkWithPercentEscape = link.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) {
println(linkWithPercentEscape)
if let url = NSURL(string: linkWithPercentEscape) {
println(url)
if UIApplication.sharedApplication().canOpenURL(url) {
UIApplication.sharedApplication().openURL(url)
}
}
}