123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- //
- // AppStoreReview.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/6/18.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- import StoreKit
- let kAppStoreAppId = "1476038871"
- class AppStoreManager: NSObject {
- static let shared : AppStoreManager = AppStoreManager()
- /// 跳转到appStoreUrl
- let kAppStore = String(describing: "https://itunes.apple.com/cn/app/\(kAppStoreAppId)")
- ///跳转到appStore评论
- let kAppStoreReview = String(describing: "https://itunes.apple.com/cn/app/\(kAppStoreAppId)?action=write-review")
- var viewController:UIViewController?
-
- /// 跳转到AppStore
- func appStore() {
- let kAppStoreURL = URL(string: kAppStore)
- if #available(iOS 10, *) {
- UIApplication.shared.open(kAppStoreURL!, options: [:], completionHandler: nil)
- } else {
- UIApplication.shared.openURL(kAppStoreURL!)
- }
- }
-
- /// 跳转到AppStore评论
- func appStoreReview() {
- let kAppStoreReviewURL = URL(string: kAppStore)
- if #available(iOS 10, *) {
- UIApplication.shared.open(kAppStoreReviewURL!, options: [:], completionHandler: nil)
- } else {
- UIApplication.shared.openURL(kAppStoreReviewURL!)
- }
- }
-
- ///只能评分,且一年只能使用三次弹框。
- func storeReviewController() {
- if #available(iOS 10.3, *) {
- SKStoreReviewController.requestReview()
- } else {
- appStoreReview()
- }
- }
-
- ///内部加载AppStore
- func webAppStore(viewController:UIViewController) {
- self.viewController = viewController
- let storeProductViewContorller = SKStoreProductViewController()
- storeProductViewContorller.delegate = self
- storeProductViewContorller.loadProduct(withParameters: [SKStoreProductParameterITunesItemIdentifier:kAppStoreAppId]) { (result, error) in
- if result {
- viewController.present(storeProductViewContorller, animated: true, completion: {
-
- })
- }else {
- SwiftProgressHUD.shared().showText("加载AppStore失败")
- }
- }
- }
- }
- extension AppStoreManager: SKStoreProductViewControllerDelegate {
- func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
- self.viewController?.dismiss(animated: true) {
-
- }
- }
- }
|