AppStoreManager.swift 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // AppStoreReview.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/6/18.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import StoreKit
  10. let kAppStoreAppId = "1476038871"
  11. class AppStoreManager: NSObject {
  12. static let shared : AppStoreManager = AppStoreManager()
  13. /// 跳转到appStoreUrl
  14. let kAppStore = String(describing: "https://itunes.apple.com/cn/app/\(kAppStoreAppId)")
  15. ///跳转到appStore评论
  16. let kAppStoreReview = String(describing: "https://itunes.apple.com/cn/app/\(kAppStoreAppId)?action=write-review")
  17. var viewController:UIViewController?
  18. /// 跳转到AppStore
  19. func appStore() {
  20. let kAppStoreURL = URL(string: kAppStore)
  21. if #available(iOS 10, *) {
  22. UIApplication.shared.open(kAppStoreURL!, options: [:], completionHandler: nil)
  23. } else {
  24. UIApplication.shared.openURL(kAppStoreURL!)
  25. }
  26. }
  27. /// 跳转到AppStore评论
  28. func appStoreReview() {
  29. let kAppStoreReviewURL = URL(string: kAppStore)
  30. if #available(iOS 10, *) {
  31. UIApplication.shared.open(kAppStoreReviewURL!, options: [:], completionHandler: nil)
  32. } else {
  33. UIApplication.shared.openURL(kAppStoreReviewURL!)
  34. }
  35. }
  36. ///只能评分,且一年只能使用三次弹框。
  37. func storeReviewController() {
  38. if #available(iOS 10.3, *) {
  39. SKStoreReviewController.requestReview()
  40. } else {
  41. appStoreReview()
  42. }
  43. }
  44. ///内部加载AppStore
  45. func webAppStore(viewController:UIViewController) {
  46. self.viewController = viewController
  47. let storeProductViewContorller = SKStoreProductViewController()
  48. storeProductViewContorller.delegate = self
  49. storeProductViewContorller.loadProduct(withParameters: [SKStoreProductParameterITunesItemIdentifier:kAppStoreAppId]) { (result, error) in
  50. if result {
  51. viewController.present(storeProductViewContorller, animated: true, completion: {
  52. })
  53. }else {
  54. SwiftProgressHUD.shared().showText("加载AppStore失败")
  55. }
  56. }
  57. }
  58. }
  59. extension AppStoreManager: SKStoreProductViewControllerDelegate {
  60. func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
  61. self.viewController?.dismiss(animated: true) {
  62. }
  63. }
  64. }