Uber button doesn't display price, but only time - ios

This is my first time using Uber api. I followed the instructions clearly, but it never really mentioned how to display price estimate in the button. My code magically displays the time( dunno why or how). Please explain how to display price as well. Both server token and client ID have been integrated in the info.plist file.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = RideRequestButton()
view.addSubview(button)
button.center = view.center
let ridesClient = RidesClient()
let dropOffLocation = CLLocation(latitude: 20.301647, longitude: 85.819135)
let pickUpLocation = CLLocation(latitude : 20.323706, longitude: 85.814981)
let builder = RideParametersBuilder()
builder.pickupLocation = pickUpLocation
builder.pickupNickname = "Home"
builder.dropoffLocation = dropOffLocation
builder.dropoffNickname = "Mayfair Lagoon, Bhubaneswar"
var productID = ""
ridesClient.fetchProducts(pickupLocation: pickUpLocation) { (product, response) in
productID = product[1].productID
print("🥒\(productID)")
}
ridesClient.fetchPriceEstimates(pickupLocation: pickUpLocation, dropoffLocation: dropOffLocation) { (price, response) in
print(price[0].estimate!,"🍚")
}
ridesClient.fetchTimeEstimates(pickupLocation: pickUpLocation) { (time, response) in
print("🥕",time[0].estimate,"🥕")
}
builder.productID = productID
button.setContent()
button.rideParameters = builder.build()
button.loadRideInformation()
}
}

Button will Deeplink into the Uber App and will simply open up the app. In order to see real-time fare estimates and pickup ETA information you will need to pass additional parameters to it. The Ride Request Button can accept optional parameters to pre-load some information into the ride request. You can see how to do it in the Uber documentation. Also this is explained here on the GitHub
Please, check out StackOverflow thread here.
It is explained and documented how to manage this issue.

Please check it out below link
Display ETA and estimated money option for my "Ride there with Uber" button

Related

Unable to post deep link to Facebook via iOS application

I am trying to use the FBSDK, specifically FBSDKShareKit to let users post a deep link to their wall from my app. I have my App set up with Facebook Developers (I know this isn't the issue because my app users sign in with Facebook with no problem) and have a scheme suffix associated with the app.
My application's info.plist has the same suffix set. I know this works because when opening a URL with this suffix from Safari, it navigates to my application.
When opening a URL, my app delegate checks if the URL host matches a certain string, if it does, I then check if the URL path matches a certain string. If both of these match, then I parse the parameters passed from the URL, create a custom object (in this case, an event), instantiate a view controller, and populate that view controller with the custom object's properties.
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if url.host != "www.mywebsite.app" {
return false
} else if url.path == "/sharedEvent" {
if let parameters = url.queryParameters {
//Get params from url
let name = parameters["name"]!
let description = parameters["description"]!
let lat = parameters["lat"]!.CGFloatValue()
let lng = parameters["lng"]!.CGFloatValue()
let startTime = Int(parameters["startTime"]!)!
let endTime = Int(parameters["endTime"]!)!
let categories = parameters["categories"]!
let priority = Int(parameters["priority"]!)!
let id = parameters["id"]!
let userId = parameters["userId"]!
let userName = parameters["userName"]!
let userEmail = parameters["userEmail"]!
let photoURLs = parameters["photoURLs"]!
let isVerified = Int(parameters["isVerified"]!)
//Create event from parameters
let sharedEvent = Event(name: name, description: description, lat: lat, long: lng, startTime: Date(timeIntervalSince1970: Double(startTime)), endTime: Date(timeIntervalSince1970: Double(endTime)), categories: [categories], priority: priority, id: id, userId: userId, userName: userName, userEmail: userEmail, photoURLs: [photoURLs], isVerified: isVerified!)
//Instantiate eventVC
let storyboard = UIStoryboard(name: "Main", bundle: .main)
let eventVC = storyboard.instantiateViewController(withIdentifier: "EventViewController") as! EventViewController
eventVC.event = sharedEvent
eventVC.userId = userId
eventVC.userEmail = userEmail
eventVC.userName = userName
DispatchQueue.main.async {
self.window!.rootViewController!.presentedViewController?.present(eventVC, animated: true, completion: nil)
}
}
return true
}
This code works as I've tested it by opening a URL from another app with some parameters, and the respective view controller is presented upon the app opening. A URL might look something like this:
fb1068346896678533://www.hootevents.app/sharedEvent?name=Some%20Name&description=Some%20description&lat=38.7016&lng=-90.447&startTime=1548466210&endTime=1551058140&categories=lhw9bs31nr2twlx&priority=1&id=15510581401548012896PfZLZCzDUh&userId=f5qLpyu4XNWa4eJI17sBi71bIw23&userName=David%20Chopin&userEmail=chopindavidg#gmail.com&photoURLs=https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/1200px-Google_2015_logo.svg.png&isVerified=1
My issue lies with actually presenting the deep link via Facebook. I've tried two approaches:
Using FBSDKShareKit's FBSDKShareButton by setting the button's shareContent to a FBSDKShareLinkContent with a content url equal to the one shown above. Doing this results in a greyed out, i.e. disabled, FBSDKShareButton. Changing the content's URL to something like "www.google.com" enables the button, meaning that Facebook doesn't like my URL for some reason.
let button = FBSDKShareButton()
let shareContent = FBSDKShareLinkContent()
content.contentURL = URL(string: "fb1068346896678533://www.hootevents.app/sharedEvent?name=Some%20Name&description=Some%20description&lat=38.7016&lng=-90.447&startTime=1548466210&endTime=1551058140&categories=lhw9bs31nr2twlx&priority=1&id=15510581401548012896PfZLZCzDUh&userId=f5qLpyu4XNWa4eJI17sBi71bIw23&userName=David%20Chopin&userEmail=chopindavidg#gmail.com&photoURLs=https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/1200px-Google_2015_logo.svg.png&isVerified=1")
button.shareContent = content
Using iOS's Social framework to instantiate an SLComposeViewController, setting said view controller's URL to the same one above, and presenting the view controller. Upon posting through Facebook, I'm prompted with the error message "There was a problem sharing your link." Again, when replacing the URL in question with "www.google.com," the post goes through successfully, indicating, again, that Facebook doesn't like the deep link I'm providing for some reason.
#IBAction func shareButtonPressed(_ sender: Any) {
let vc = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
vc?.add(loadedImages.first?.image)
vc!.add(URL(string: shareURL))
for photo in self.loadedImages {
vc!.add(photo.image!)
}
present(vc!, animated: true, completion: nil)
}
So, in conclusion, I believe that the issue here lies with the fact that Facebook won't allow me to post:
fb1068346896678533://www.hootevents.app/sharedEvent?name=Some%20Name&description=Some%20description&lat=38.7016&lng=-90.447&startTime=1548466210&endTime=1551058140&categories=lhw9bs31nr2twlx&priority=1&id=15510581401548012896PfZLZCzDUh&userId=f5qLpyu4XNWa4eJI17sBi71bIw23&userName=David%20Chopin&userEmail=chopindavidg#gmail.com&photoURLs=https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/1200px-Google_2015_logo.svg.png&isVerified=1
on behalf of users. If this is the case, how am I supposed to format my deep link so that users can post it to their wall from my app, effectively sharing events with their Facebook friends and, ideally, driving more traffic to my app?
It seems all I had to do was wait a while (I guess it can take up to 48 hours for the link to start working?).
Note that the Facebook app does not allow users to navigate to another app via universal/deep linking. Their in-app browser is designed to not allow this to happen. There are some workaround, most notably Branch.io, which allows users to get use out of their universal links through Facebook.

iOS MapKit Get Places information and Reviews

I'm using mapkit and able to get Address for a particular location
let firstPlacemark = placemarks,
let addressDictionary = firstPlacemark.addressDictionary else { return }
// let street = addressDictionary["Street"]
// let city = addressDictionary["City"]
// let state = addressDictionary["State"]
// let zip = addressDictionary["ZIP"]
print(addressDictionary.description)
if let array = addressDictionary["FormattedAddressLines"] as? [Any] {
let address = array.map { "\($0)" }.joined(separator: ",\n")
print("Address : \(address)")
}
But Can we get more information like reviews contact no. images etc. Like Apple Maps shows (Observe Screeenshot)
Is there any API available in iOS for this or it will be provided via TripAdvisor???
P.S: I don't want to Any Google API.
Dear down voters if don't know the answers then kindly don't waste my points. It's easy to downvote, but you never know how much efforts has been added to earn those points.
OR Kindly provide me solution or show me if question is duplicate.
You can use Tripadvisor API
https://developer-tripadvisor.com/content-api/documentation/
ex.
http://api.tripadvisor.com/api/partner/2.0/location/155507?key=YOURKEY

Rides-ios-sdk - Get cheapest product

I'm using the Uber-SDK for an iOS app. Over the last few days, I can get the cheapest product with ridesClient.fetchCheapestProduct(). But today, that function always returns a nil value.
Is this a problem with the server or SDK? Please help me with this issue.
(I'm in Vietnam and my client_id still works fine for Android)
This is my code:
let ridesClient = RidesClient()
let button = RideRequestButton()
override func viewDidLoad() {
super.viewDidLoad()
let pickupLocation = CLLocation(latitude: 37.775159, longitude: -122.417907)
let dropoffLocation = CLLocation(latitude: 37.6213129, longitude: -122.3789554)
//make sure that the pickupLocation and dropoffLocation is set in the Deeplink
var builder = RideParametersBuilder()
.setPickupLocation(pickupLocation)
// nickname or address is required to properly display destination on the Uber App
.setDropoffLocation(dropoffLocation, nickname: "San Francisco International Airport")
// use the same pickupLocation to get the estimate
ridesClient.fetchCheapestProduct(pickupLocation: pickupLocation, completion: { product, response in
if let productID = product?.productID { //check if the productID exists
builder = builder.setProductID(productID)
self.button.rideParameters = builder.build()
// show estimate in the button
self.button.loadRideInformation()
}
})
// center the button (optional)
button.center = view.center
//put the button in the view
view.addSubview(button)
}
Make sure you set a server token in your Info.plist. This allows the RidesClient() to make a price estimate API call.
Copy this snippet into your Info.plist (right click and select Open As > Source Code) and replace YOUR_SERVER_TOKEN with the Server Token from your dashboard (make sure you use the server token corresponding to your client ID).
<key>UberServerToken</key>
<string>YOUR_SERVER_TOKEN</string>

SKScene and URLQueryItems in Swift3?

Ok, I am new to URL querying and this whole aspect of Swift and need help. As is, I have an iMessage app that contains and SKScene. For the users to take turns playing the game, I need to send the game back and forth in messages within 1 session as I learned here : https://medium.com/lost-bananas/building-an-interactive-imessage-application-for-ios-10-in-swift-7da4a18bdeed.
So far I have my scene all working however Ive poured over Apple's ice cream demo where they send the continuously-built ice cream back and forth, and I cant understand how to "query" everything in my SKScene so I can send the scene.
I'm unclear as to how URLQueryItems work as the documentation does not relate to sprite kit scenes.
Apple queries their "ice cream" in its current state like this:
init?(queryItems: [URLQueryItem]) {
var base: Base?
var scoops: Scoops?
var topping: Topping?
for queryItem in queryItems {
guard let value = queryItem.value else { continue }
if let decodedPart = Base(rawValue: value), queryItem.name == Base.queryItemKey {
base = decodedPart
}
if let decodedPart = Scoops(rawValue: value), queryItem.name == Scoops.queryItemKey {
scoops = decodedPart
}
if let decodedPart = Topping(rawValue: value), queryItem.name == Topping.queryItemKey {
topping = decodedPart
}
}
guard let decodedBase = base else { return nil }
self.base = decodedBase
self.scoops = scoops
self.topping = topping
}
}
fileprivate func composeMessage(with iceCream: IceCream, caption: String, session: MSSession? = nil) -> MSMessage {
var components = URLComponents()
components.queryItems = iceCream.queryItems
let layout = MSMessageTemplateLayout()
layout.image = iceCream.renderSticker(opaque: true)
layout.caption = caption
let message = MSMessage(session: session ?? MSSession())
message.url = components.url!
message.layout = layout
return message
}
}
But I cant find out how to "query" an SKScene. How can I "send" an SKScene back and forth? Is this possible?
You do not need to send an SKScene back and forth :) What you need to do is send the information relating to your game set up - such as number of turns, or whose turn it is, or whatever, as information that can be accessed by your app at the other end to build the scene.
Without knowing more about how your scene is set up and how it interacts with the information received for the other player's session, I can't tell you a lot in terms of specifics. But, what you need to do, if you are using URLQueryItems to pass the information, simply retrieve the list of query items in your scene and set up the scene based on the received values.
If you have specific questions about how this could be done, if you either share the full project, or post the relevant bits of code as to where you send out a message from one player and how the other player receives the information and sets up the scene, I (or somebody else) should be able to help.
Also, if you look at composeMessage in the code you posted above, you will see how in that particular code example the scene/game information was being sent to the other user. At the other end of the process, the received message's URL parameter would be decomposed to get the values for the various query items and then the scene would be set up based on those values. Look at how that is done in order to figure out how your scene should be set up.

Can't receive PubNub message unless I publish a message first

In my Swift application, I instantiate PubNub on viewDidLoad with the
correct configuration and then join a channel. However, it looks as if it
doesn't join the channel at all unless I fire the Send button action to
send a message (I threw the config/join channel code in the Send button
just to see if it would work). The code in the Send button function is
identical to the code in the viewDidLoad, but the code in viewDidLoad is
still ignored. This is frustrating because the current user on my app won't
receive messages sent to the channel unless the user first sends a message.
Here's the code in the view controller (I removed a lot of the code so it's easier to look at. If you think the issue lies elsewhere I can post more):
class MessageViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, PNObjectEventListener{
var pubNub: PubNub!
var pnConfiguration: PNConfiguration!
var ids: String = ""
#IBAction func sendButton(sender: UIButton) {
//create Pubnub channel
pnConfiguration = PNConfiguration(publishKey: "key", subscribeKey: "key")
pnConfiguration.uuid = currentUser.objectId!
print(pnConfiguration.uuid)
pubNub = PubNub.clientWithConfiguration(pnConfiguration)
let channelName = ids as String
let channelArray: [String] = [channelName]
pubNub.subscribeToChannels(channelArray, withPresence: true)
pubNub.publish(self.messageText.text!, toChannel: channelName, compressed: false, withCompletion: nil)
pubNub.addListener(self)
self.messageText.enabled = true
self.view.userInteractionEnabled = true
dispatch_async(dispatch_get_main_queue()) {
self.messageText.text = ""
self.messageTableView.reloadData()
}
}
override func viewDidLoad() {
super.viewDidLoad()
//Query that sets self.ids = user1.objectId! + user2.objectId!
//set Pubnub config
pnConfiguration = PNConfiguration(publishKey: "key", subscribeKey: "key")
pubNub = PubNub.clientWithConfiguration(pnConfiguration)
pnConfiguration.uuid = currentUser.objectId!
//create channel
let channelName = ids as String
print(channelName)
let channelArray: [String] = [channelName]
pubNub.subscribeToChannels(channelArray, withPresence: true)
pubNub.addListener(self)
dispatch_async(dispatch_get_main_queue()) {
self.messageTableView.reloadData()
}
}
EDIT:
After looking at the logs it looks like the reason why it's not working is because it's joining a channel called "", even though the print(channelName) returns the real channel name. Why isn't it taking the channel name? Is it not the right data type?
In your code snippet I don't see any place where you set real value for ids variable which you declare at line #7. So client use value which is stored in that variable: ""
I think this variable changed during controller life-cycle and set to proper value before you hit sendButton but not available at time when view is loaded.
Best regards,
Sergey

Resources