google placepicker for ios and BackgroundMapViewController.swift - swift

I'm trying to implement google's placepicker for ios.
There is some demo code at:
https://github.com/googlemaps/maps-sdk-for-ios-samples/tree/master/GooglePlacePicker/GooglePlacePickerDemos
And i get most of it except the line in the file PickAPlaceViewController.swift
var mapViewController: BackgroundMapViewController?
In the github repo Google have provided their own class BackgroundMapViewController.
Do I need to create an instance of this class to use the place picker?
Or can I just use a GMSMapView like I ordinarily would with google maps.
Thanks.

For Google Places Controller you just need below code to show or present Places Controller in your App.
Put this in ur Button Action method :
// Create a place picker. Attempt to display it as a popover if we are on a device which
// supports popovers.
let config = GMSPlacePickerConfig(viewport: nil)
let placePicker = GMSPlacePickerViewController(config: config)
placePicker.delegate = self
placePicker.modalPresentationStyle = .popover
placePicker.popoverPresentationController?.sourceView = pickAPlaceButton
placePicker.popoverPresentationController?.sourceRect = pickAPlaceButton.bounds
// Display the place picker. This will call the delegate methods defined below when the user
// has made a selection.
self.present(placePicker, animated: true, completion: nil)
Hope This will helps to show Place Picker in your app.

Related

Localization not working in presenting UIActivityViewController in swift 5

My app supports both LTR and RTL. It works fine for all cases. If i change app language from app settings then in every screen language is updated and works fine.
When i press share button in app. Below code is executed.Here i want to show share picker in my app's selected language. But it doesn't show it in my app's language.
let text = NSLocalizedString("I liked this view in app", comment: "")
// set up activity view controller
let activityViewController = UIActivityViewController(activityItems: [text, urls], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
// exclude some activity types from the list (optional)
// activityViewController.excludedActivityTypes = [ UIActivity.ActivityType.airDrop, UIActivity.ActivityType.postToFacebook ]
// present the view controller
self.present(activityViewController, animated: true, completion: nil)`
I have tried below code to update share view language change but it didn't work.
if ( Language.currentLanguage == .arabic) {
activityViewController.accessibilityLanguage = "ar-SA"
}
else{
activityViewController.accessibilityLanguage = "en-US"
}
I have also tried below code but it is also not working.
if ( Language.currentLanguage == .arabic) {
activityViewController.view.semanticContentAttribute = .forceRightToLeft
}
else{
activityViewController.view.semanticContentAttribute = .forceLeftToRight
}
Anyone could help me with this issue ?
PS
For share picker you can refer below screenshot :
A solution which worked for me. Go to your Info.plist and add Localized resources can be mixed with Boolean YES or NO to it, and check the result.
As mentioned in Core Foundation Keys:
CFBundleAllowMixedLocalizations
CFBundleAllowMixedLocalizations (Boolean - iOS, macOS) specifies
whether the bundle supports the retrieval of localized strings from
frameworks. This key is used primarily by Foundation tools that link
to other system frameworks and want to retrieve localized resources
from those frameworks.

Google Places Autocomplete Delegate not set

I am setting the delegate of the autocomplete view controller to the current class, which has an autocompleteviewcontrollerdelegate extension. This has has always worked in the past, but recently I am getting an error message printing out that says the delegate for the autocomplete controller is not set and I can confirm the delegate is no longer being called. I have the print(self) line to check that I am in fact setting the correct class to be the delegate. I have this exact same setup in another part of my app that is working fine. Any suggestions on how to debug this issue?
#objc func searchButton() {
print(self)
let acController = GMSAutocompleteViewController()
acController.delegate = self
acController.autocompleteBounds = getBounds(latitude: latitude!, longitude: longitude!)
// Specify a filter.
//let filter = GMSAutocompleteFilter()
//filter.type = establishment
//acController.autocompleteFilter = filter
present(acController, animated: true, completion: nil)
}
In my viewwillDisappear method I pop the view controller so that if the user navigated away from the page with the tab bar controller the next time they navigate to the page they will be on the main page. Whenever the autocomplete view controller was appearing the parent viewcontroller was getting popped off the stack and killing off the delegate.

How to use GMSPlacePickerViewController class?

I created the picker as follows:
let placePicker = GSMPlacePickerViewController(config: config)
placePicker.delegate?.placePicker(viewController: GSMPlacePickerViewController, didPick: GSMPlace)
In the second line of the code above, how can I store the place the user picks inside a variable of my own so later I can access its properties like the coordinates?
I am confused on how to implement GSMPlacePickerViewController method and couldn't find examples online.
As from the GSMPlacePickerViewController docs, it says that I don't have to implement the first parameter and I could leave it empty if I understood it correctly
Implementations of this method should dismiss the view controller as
the view controller will not dismiss itself.
So my problem now, is storing the user selected location in a variable of my own.
How should I go to achieving that?
Add GMSPlacePickerViewControllerDelegate to your view controller like so:
class YourViewController: GMSPlacePickerViewControllerDelegate {
}
Then add the delegate method within said VC which will be called when the user picks the place. You then dismiss and access place data like below:
func placePicker(_ viewController: GMSPlacePickerViewController, didPick place: GMSPlace) {
placePicker.dismiss(animated: true, completion: nil)
let location = CLLocation(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
}

Giving a xib multiple file owners

I am attempting to have a header view appear on multiple viewcontroller's tableviews. I do not know what I should set the xib files owner class to. I am trying to do this so that I can call a button on the header's action. I have already tried UIViewController and have had no luck. Any help would be appreciate.
The best (in my opinion) if you create a dedicated controller class for the view. You can load and add the loaded ViewController like:
let cmVC = ColorMenuVC(nibName: "ColorMenu", bundle: Bundle.main, textProperty: _textProperty!)
//font menu initialization & settings
cmVC.modalPresentationStyle = UIModalPresentationStyle.popover
//popover settings
let popover = cmVC.popoverPresentationController
popover?.delegate = self
popover?.barButtonItem = sender
popover?.permittedArrowDirections = UIPopoverArrowDirection.any
//presenting
present(cmVC, animated: true, completion: nil)
This example for Popovers, but I hope this will helpful. The ColorMenuVC is extending the UIViewController, but here is the original class how to init:
https://developer.apple.com/reference/uikit/uiviewcontroller/1621487-nibname

How does presentViewController display the view?

I'm curious as to what the presentViewController does with the first parameter, imagePickerController. Given the way I assigned imagePickerController's properties, will the presentViewController use all that information to display the view?
#IBAction func imageFromPhotoLibrary(sender: UITapGestureRecognizer) {
// Hide the keyboard.
myTextField.resignFirstResponder()
// UIImagePickerController is a view controller that lets a user pick media from their photo library.
let imagePickerController = UIImagePickerController()
// Only allow photos to be picked, not taken.
imagePickerController.sourceType = .PhotoLibrary
// Make sure ViewController is notified when the user picks an image.
imagePickerController.delegate = self
presentViewController(imagePickerController, animated: true, completion: nil)
}
presentViewController won't use any of the options. The imagePickerController you passed in will use those options.
Since the Apple APIs are pretty well designed, presentViewController does one thing (SRP), and does exactly what it says it does... presents the view controller you pass it.
The imagePickerController is in charge controlling the view of the image picker.