NYSwRouter.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // NYSwRouter.swift
  3. // JSJP_Student_sw
  4. //
  5. // Created by Ning.ge on 2023/5/30.
  6. //
  7. import UIKit
  8. import URLNavigator
  9. enum NYSwPushType {
  10. case recommend_rank
  11. case recommend_player
  12. case live_room
  13. case live_all
  14. case drama_recommend
  15. }
  16. enum NYSwOpenType: String {
  17. case area = "http://live.bilibili.com/app/area"
  18. case common = "http://live.bilibili.com/app/mytag/"
  19. case attention = "http://live.bilibili.com/app/myfollow/"
  20. case all = "http://live.bilibili.com/app/all-live/"
  21. case login = "Bilibili://app/login"
  22. }
  23. extension NYSwPushType {
  24. var path:String {
  25. switch self {
  26. case .recommend_rank:
  27. return "Bilibili://recommend/rank"
  28. case .recommend_player:
  29. return "Bilibili://recommend/player"
  30. case .live_all:
  31. return "Bilibili://live/recommend"
  32. case .live_room:
  33. return "Bilibili://live/room"
  34. case .drama_recommend:
  35. return "Bilibili://drama/recommend"
  36. }
  37. }
  38. }
  39. class NYSwRouter {
  40. @discardableResult
  41. class func push(_ type:NYSwPushType, context: Any? = nil) -> UIViewController? {
  42. return navigator.push(type.path, context: context)
  43. }
  44. @discardableResult
  45. class func push(_ url:String) -> UIViewController? {
  46. return navigator.push(url)
  47. }
  48. @discardableResult
  49. class func open(_ url:String) -> Bool? {
  50. guard let header = url.components(separatedBy: "?").first,
  51. let _ = NYSwOpenType(rawValue: header)
  52. else {
  53. NYSwToaster.show("需要跳转的路径未找到,请先注册!")
  54. return nil
  55. }
  56. return navigator.open(url)
  57. }
  58. }