你们能帮我把下面的代码翻译成Swift吗?
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.apple.com/de/app/x-gift/id839686104?mt=8&uo=4"]];
(或者我必须使用此链接: itms://itunes.apple.com/app/id839686104?)
提前感谢!
发布于 2014-09-17 15:48:24
这里。但我强烈建议您学习Swift的基础知识!
UIApplication.sharedApplication().openURL(NSURL(string: "itms://itunes.apple.com/de/app/x-gift/id839686104?mt=8&uo=4")!)
如果你想在Swift 5中打开AppStore
if let url = URL(string: "itms-apps://apple.com/app/id839686104") {
UIApplication.shared.open(url)
}
发布于 2016-11-05 11:42:02
Swift 3语法,并使用'if let‘进行了改进
if let url = URL(string: "itms-apps://itunes.apple.com/app/id1024941703"),
UIApplication.shared.canOpenURL(url){
UIApplication.shared.openURL(url)
}
更新7/5/17 (谢谢你指出这一点):
if let url = URL(string: "itms-apps://itunes.apple.com/app/id1024941703"),
UIApplication.shared.canOpenURL(url)
{
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
发布于 2016-04-12 05:43:57
我使用这个组合,它对价格/购物更好。
(部分来自here)
@IBAction func rateMe(sender: AnyObject) {
if #available(iOS 8.0, *) {
openStoreProductWithiTunesItemIdentifier("107698237252");
} else {
var url = NSURL(string: "itms://itunes.apple.com/us/app/xxxxxxxxxxx/id107698237252?ls=1&mt=8")
if UIApplication.sharedApplication().canOpenURL(url!) == true {
UIApplication.sharedApplication().openURL(url!)
}
}
}
func openStoreProductWithiTunesItemIdentifier(identifier: String) {
let storeViewController = SKStoreProductViewController()
storeViewController.delegate = self
let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier]
storeViewController.loadProductWithParameters(parameters) { [weak self] (loaded, error) -> Void in
if loaded {
// Parent class of self is UIViewContorller
self?.presentViewController(storeViewController, animated: true, completion: nil)
}
}
}
func productViewControllerDidFinish(viewController: SKStoreProductViewController) {
viewController.dismissViewControllerAnimated(true, completion: nil)
}
别忘了导入和委派:
import StoreKit
class RateMeViewController: UIViewController, SKStoreProductViewControllerDelegate {
https://stackoverflow.com/questions/25882936
复制相似问题