ios 如何快速添加费率按钮的链接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27755069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I add a link for a rate button with swift?
提问by Luis Felipe
First I don't know how to get the link before I submit my app, and if the link is for each country app store or is it universal?
首先,我在提交我的应用程序之前不知道如何获取链接,以及该链接是针对每个国家/地区的应用程序商店还是通用的?
Also I don't know if the way to do it is just by putting the link there like:
另外我不知道这样做的方法是否只是将链接放在那里,例如:
@IBAction func rate(sender: AnyObject) {
UIApplication.sharedApplication().openURL(NSURL(string : "webLinkHere")!)
}
Or should I use another way to do this?
或者我应该使用另一种方式来做到这一点?
Thanks
谢谢
回答by YannSteph
Try This, change appIdin your method by your App ID
试试这个,通过你的App ID在你的方法中更改appId
Swift 5
斯威夫特 5
import StoreKit
func rateApp() {
if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
} else if let url = URL(string: "itms-apps://itunes.apple.com/app/" + "appId") {
if #available(iOS 10, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
}
Swift 3 \ 4
斯威夫特 3 \ 4
func rateApp() {
guard let url = URL(string: "itms-apps://itunes.apple.com/app/" + "appId") else {
return
}
if #available(iOS 10, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
id959379869This is the id when you go on your Itune page of your app
id959379869这是您进入应用程序的 Itune 页面时的 ID
Example :https://itunes.apple.com/fr/app/hipster-moustache/id959379869?mt=8
示例:https: //itunes.apple.com/fr/app/hipster-mustache/id959379869?mt=8
How get the ID:
身获取方式:
- Itunesconnect account
- My Apps
- Click on "+" Button
- New iOS App
- Fill require details
- After filling all details goto your App
- Click on More Button
- View on AppStore
- It will redirect you to your App URL this will be universal
- Look Http URL
- iTunes连接帐户
- 我的应用
- 点击“+”按钮
- 新的 iOS 应用
- 填写要求详情
- 填写所有详细信息后转到您的应用程序
- 点击更多按钮
- 在 AppStore 上查看
- 它会将您重定向到您的应用程序 URL,这将是通用的
- 看 Http URL
回答by Simon
This is working the best for me. Directs the user straight to the 'Write A Review' composer of the application.
这对我来说是最好的。将用户直接定向到应用程序的“撰写评论”编辑器。
Swift 3.1(Support for iOS10 and below)
Swift 3.1(支持 iOS10 及以下)
Introduces new action=write-review
推出新的 action=write-review
let appID = "959379869"
if let checkURL = URL(string: "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=\(appID)&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8") {
open(url: checkURL)
} else {
print("invalid url")
}
...
func open(url: URL) {
if #available(iOS 10, *) {
UIApplication.shared.open(url, options: [:], completionHandler: { (success) in
print("Open \(url): \(success)")
})
} else if UIApplication.shared.openURL(url) {
print("Open \(url)")
}
}
Tested and works on Swift 2.2
在 Swift 2.2 上测试和工作
let appID = "959379869" // Your AppID
if let checkURL = NSURL(string: "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=\(appID)&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8") {
if UIApplication.sharedApplication().openURL(checkURL) {
print("url successfully opened")
}
} else {
print("invalid url")
}
回答by Arvind
Now after iOS 10.3+
现在在 iOS 10.3+ 之后
The SKStoreReviewController allows users to rate an app directly from within the app through a dialog box. The only downsite is that you can only request StoreKit to display the dialog, but can't be sure if it will.
SKStoreReviewController 允许用户通过对话框直接从应用程序内评价应用程序。唯一的缺点是您只能请求 StoreKit 显示对话框,但不能确定它是否会显示。
import StoreKit
func requestToRate() {
SKStoreReviewController.requestReview()
}
回答by Alfi
Swift 4
斯威夫特 4
let url = URL(string: "itms-apps:itunes.apple.com/us/app/apple-store/id\(YOURAPPID)?mt=8&action=write-review")!
UIApplication.shared.openURL(url)
回答by Mahmud Ahsan
You can use the following function and replace the APP_ID with your one. Calling this function will open the app in app store link and user will see the Review page where he can click and write a review easily.
您可以使用以下功能并将 APP_ID 替换为您的功能。调用此函数将在应用商店链接中打开应用程序,用户将看到评论页面,在那里他可以轻松点击并撰写评论。
func rateApp(){
UIApplication.sharedApplication().openURL(NSURL(string : "itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=\(APP_ID)&onlyLatestVersion=true&pageNumber=0&sortOrdering=1)")!);
}
回答by SergPanov
For iOS 10.3+ you can use SKStoreReviewController with simple dialog, and choose rating in alert-style window. To use it, you should import StoreKit library. So, universal way to rate your app inside itself is like this:
对于 iOS 10.3+,您可以使用带有简单对话框的 SKStoreReviewController,并在警报样式窗口中选择评级。要使用它,您应该导入 StoreKit 库。因此,对您的应用程序本身进行评分的通用方法是这样的:
import StoreKit
func rateApp(){
if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
} else {
guard let url = URL(string: "itms-apps://itunes.apple.com/ru/app/cosmeteria/id1270174484") else {
return
}
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
}
And when you try to launch it in simulator, you won't see App Store window, so try it on device and it gonna work. This way covers all iOS versions, using all abilities. And the part of path in you application address "/us/app" means your App Store localisation, for example "us" means USA. You can easily find your app id in address string just by opening app in App Store in any browser.To get the link, just copy address in browser. Changing "https://" for "itms-apps://" lets you to open app in App Store application, while "https" opens web page in Safari
当您尝试在模拟器中启动它时,您将看不到 App Store 窗口,因此在设备上尝试它会起作用。这种方式涵盖所有 iOS 版本,使用所有功能。而你应用地址中的路径部分“/us/app”表示你的App Store本地化,例如“us”表示美国。只需在任何浏览器中打开 App Store 中的应用程序,您就可以轻松地在地址字符串中找到您的应用程序 ID。要获取链接,只需在浏览器中复制地址即可。将“https://”更改为“itms-apps://”可让您在 App Store 应用程序中打开应用程序,而“https”在 Safari 中打开网页
回答by Cliff Weitzman
WARNING: If you are running your app on a simulator
警告:如果您在模拟器上运行您的应用程序
UIApplication.sharedApplication().openURL(NSURL(string : "url")!)
will not work because there is no app store in the simulator. In order to test this functionality you must run your app on a device.
将无法工作,因为模拟器中没有应用商店。为了测试此功能,您必须在设备上运行您的应用程序。
回答by ThiagoAM
Swift 5.1:The following function sends your user directly to the review section of ANY store, not just on the American one:
Swift 5.1:以下功能将您的用户直接发送到任何商店的评论部分,而不仅仅是美国商店:
func rateApp(id : String) {
guard let url = URL(string : "itms-apps://itunes.apple.com/app/id\(id)?mt=8&action=write-review") else { return }
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
Usage:
用法:
rateApp(id: "1287000522")
Important Note:This doesn't work on simulator! Test it on a real device.
重要提示:这不适用于模拟器!在真实设备上进行测试。
回答by matiasverde
Swift 3
斯威夫特 3
func rateApp(){
UIApplication.shared.open(URL(string : "itms-apps://itunes.apple.com/app/id959379869")!, options: [:]) { (done) in
// Handle results
}}
id959379869 This is the id when you go on your iTunes page of your app
id959379869 这是您进入应用程序的 iTunes 页面时的 ID
回答by Krunal Darji
Goto your itunesconnect account -> My Apps -> Click on "+" Button ->New iOS App -> Fill require details -> After filling all details goto your App -> Click on More Button -> View on AppStore -> it will redirect you to your App URL this will be universal & will be same after your app goes live .
转到您的itunesconnect帐户->我的应用程序->单击“+”按钮->新建iOS应用程序->填写要求详细信息->填写所有详细信息后转到您的应用程序->单击更多按钮->在AppStore上查看->它将将您重定向到您的应用程序 URL,这将是通用的,并且在您的应用程序上线后将保持不变。