@@ -9,21 +9,21 @@ import UIKit
99public enum LyftDeepLinkBehavior {
1010 case native
1111 case web
12-
12+
1313 fileprivate var baseUrl : URL ? {
1414 switch self {
15- case . native:
16- return URL ( string: " lyft:// " )
17-
18- case . web:
19- return URL ( string: " https://ride.lyft.com/ " )
15+ case . native:
16+ return URL ( string: " lyft://ridetype " )
17+
18+ case . web:
19+ return URL ( string: " https://ride.lyft.com/u " )
2020 }
2121 }
2222}
2323
2424/// Collection of deep links into the main Lyft application
2525public struct LyftDeepLink {
26-
26+
2727 /// Prepares to request a ride with the given parameters
2828 ///
2929 /// - parameter behavior: The deep linking mode to use for this deep link
@@ -36,59 +36,42 @@ public struct LyftDeepLink {
3636 to destination: CLLocationCoordinate2D ? = nil ,
3737 couponCode: String ? = nil )
3838 {
39- let action : String
4039 var parameters = [ String: Any] ( )
4140 parameters [ " partner " ] = LyftConfiguration . developer? . clientId
4241 parameters [ " credits " ] = couponCode
43-
44- switch behavior {
45- case . native:
46- action = " ridetype "
47- parameters [ " id " ] = kind. rawValue
48- parameters [ " pickup[latitude] " ] = pickup. map { $0. latitude }
49- parameters [ " pickup[longitude] " ] = pickup. map { $0. longitude }
50- parameters [ " destination[latitude] " ] = destination. map { $0. latitude }
51- parameters [ " destination[longitude] " ] = destination. map { $0. longitude }
52-
53- case . web:
54- action = " request "
55- parameters [ " ride_type " ] = kind. rawValue
56- parameters [ " pickup " ] = pickup. map { " @ \( $0. latitude) , \( $0. longitude) " }
57- parameters [ " destination " ] = destination. map { " @ \( $0. latitude) , \( $0. longitude) " }
58- }
59-
60- self . launch ( using: behavior, action: action, parameters: parameters)
42+ parameters [ " id " ] = kind. rawValue
43+ parameters [ " pickup[latitude] " ] = pickup. map { $0. latitude }
44+ parameters [ " pickup[longitude] " ] = pickup. map { $0. longitude }
45+ parameters [ " destination[latitude] " ] = destination. map { $0. latitude }
46+ parameters [ " destination[longitude] " ] = destination. map { $0. longitude }
47+
48+ self . launch ( using: behavior, parameters: parameters)
6149 }
62-
63- private static func launch( using behavior: LyftDeepLinkBehavior , action: String ,
64- parameters: [ String : Any ] )
50+
51+ private static func launch( using behavior: LyftDeepLinkBehavior , parameters: [ String : Any ] )
6552 {
66- guard let originalUrl = behavior. baseUrl. flatMap ( { URL ( string: action, relativeTo: $0) } ) else {
67- return
68- }
69-
70- let request = lyftURLEncodedInURL ( request: URLRequest ( url: originalUrl) , parameters: parameters) . 0
53+ let request = lyftURLEncodedInURL ( request: URLRequest ( url: behavior. baseUrl!) , parameters: parameters) . 0
7154 guard let url = request. url else {
7255 return
7356 }
74-
57+
7558 switch behavior {
76- case . native:
77- if #available( iOS 10 . 0 , * ) {
78- UIApplication . shared. open ( url, options: [ : ] ) { success in
79- if !success {
80- self . launchAppStore ( )
81- }
59+ case . native:
60+ if #available( iOS 10 . 0 , * ) {
61+ UIApplication . shared. open ( url, options: [ : ] ) { success in
62+ if !success {
63+ self . launchAppStore ( )
8264 }
83- } else {
84- UIApplication . shared. openURL ( url)
8565 }
86-
87- case . web:
88- Safari . openURL ( url, from: UIApplication . shared. topViewController)
66+ } else {
67+ UIApplication . shared. openURL ( url)
68+ }
69+
70+ case . web:
71+ Safari . openURL ( url, from: UIApplication . shared. topViewController)
8972 }
9073 }
91-
74+
9275 @available ( iOS 10 . 0 , * )
9376 private static func launchAppStore( ) {
9477 let signUp = LyftConfiguration . signUpIdentifier
@@ -108,7 +91,7 @@ fileprivate extension UIApplication {
10891 while let viewController = topController? . presentedViewController {
10992 topController = viewController
11093 }
111-
94+
11295 return topController
11396 }
11497}
0 commit comments