Get url SFSafariViewController once it's fully loaded - ios

I'm using a SFSafariViewController. The initial url that loads redirects to another url. I need to get the current url bar that SFSafariViewController has.
It's successfully redirecting because I can see it in the url bar but I got no access not even from delegate methods.
Before that, I was using UIWebView and it worked fine but suddenly it doesn't redirect anymore.
This is my code for SFSafariViewController:
override func viewDidAppear(_ animated: Bool) {
safari = SFSafariViewController(url: URL(string:"https://api.instagram.com/oauth/authorize/?client_id=client_code&redirect_uri=http://localhost&response_type=code")!)
safari.delegate = self
self.present(safari, animated: true, completion: nil)
}
It's presenting rightly but I need access to the current url.
Thanks in advance.

Related

Wikipedia renders WkWebView and Safari differently on an iPad

This problem is iPad specific.
When I use a WKWebView inside my app, its User Agent field is identical to the one sent by Safari. However, the page returned by Wikipedia to my App includes the standard Wikipedia side-bar. Safari on the iPad does not show the side bar.
I would like WKWebview to behave the same was as Safari. I would appreciate suggestions.
You can use SFSafariViewController instead Its behaviour is identical to Safari
if let url = URL(string: urlString) {
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = true
let vc = SFSafariViewController(url: url, configuration: config)
present(vc, animated: true)
}

A delegate has not been set on an instance of GMSPlacePickerViewController before us

I've been playing around for couple days with IOS and Google Maps Api and two days ago the API was upgraded to the version 2.3 which deprecate the use of GMSPlacePicker.
Deprecation notice: GMSPlacePicker
Notice: The implementation of the place picker has changed. As of version 2.3 of the Google Places API for iOS, the GMSPlacePicker class is deprecated, replaced by GMSPlacePickerViewController. Use of the GMSPlacePicker class will only be supported until May 1, 2018. We recommend that you update your code to use GMSPlacePickerViewController when possible.
In my code I switched to GMSPlacePickerViewController however I still get an error on the logs saying :
Places API warning: A delegate has not been set on an instance of GMSPlacePickerViewController before use. Note that this may result in undefined behavior such as being unable to dismiss screens, not being notified of selections, and being unable to correctly manage object lifecycle.
Even though my class is extending the delegate
class ReportController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource,GMSPlacePickerViewControllerDelegate{
// code goes here
}
Any idea how to solve this ?
I had also the same problem I resolved this by using this code.
Here is the code .
let config = GMSPlacePickerConfig(viewport: nil)
let placePicker = GMSPlacePickerViewController(config: config)
placePicker.delegate = self
present(placePicker, animated: true, completion: nil)
Hope this will also resolve your problem
GoogleMap version 2.3
The document also make me feel confuse in version 2.3
The picture below is a picture that I crop from the google document.
This link is a document from google map SDK for this Solution
you just write the code according to document and add a one line of code below the code was accentuated by the red pen.
The code that I wrote accordingly from document below here
// The code snippet below shows how to create and display a GMSPlacePickerViewController.
#IBAction func pickPlace(_ sender: UIButton) {
let config = GMSPlacePickerConfig(viewport: nil)
let placePicker = GMSPlacePickerViewController(config: config)
placePicker.delegate = self
present(placePicker, animated: true, completion: nil)
}
// To receive the results from the place picker 'self' will need to conform to
// GMSPlacePickerViewControllerDelegate and implement this code.
func placePicker(_ viewController: GMSPlacePickerViewController, didPick place: GMSPlace) {
// Dismiss the place picker, as it cannot dismiss itself.
viewController.dismiss(animated: true, completion: nil)
print("Place name \(place.name)")
print("Place address \(String(describing: place.formattedAddress))")
print("Place attributions \(String(describing: place.attributions))")
}
func placePickerDidCancel(_ viewController: GMSPlacePickerViewController) {
// Dismiss the place picker, as it cannot dismiss itself.
viewController.dismiss(animated: true, completion: nil)
print("No place selected")
}

Trying to Open SFSafariViewController in AppDelegate via Push Notification

I am trying to open a URL using Safari when the app gets a push notification. This works successfully when the app is in the first viewcontroller. But if the app is further into the program I get an error
<SFSafariViewController: 0x10b20ae60> on <AdViewController: 0x100b14530> whose view is not in the window hierarchy!
(AdViewController is my first view controller, so it is still focused on that one. )
I have searched this site and have tried all the suggestions for this error but have come up short. Currently, my code looks like this:
if MessageUrl != nil , let url = URL(string: MessageUrl!) {
let safari = SFSafariViewController(url: url)
self.window?.rootViewController?.presentedViewController?.present(safari, animated: true, completion: nil)
}
Get top most UIViewController I used extension UIApplication in Appdeleagte from the "swift 3" answer at bottom of that page and changed my code to:
if MessageUrl != nil , let url = URL(string: MessageUrl!) {
let safari = SFSafariViewController(url: url)
UIApplication.topViewController()?.present(safari, animated: true, completion: nil)
}

Square API + OAuth: How do I sign out of my iPad app?

I am using Swift and the OAuthSwift pod to handle OAuth using an in app SFSafariViewController. Here's what it looks like for sign in:
The thing is, when I try to log out with this code:
#IBAction func signOutButtonPressed(_ sender: AnyObject) {
let svc = SFSafariViewController(url: URL(string: "https://squareup.com/logout")!)
self.present(svc, animated: true, completion: {
print("signed outttt")
appStore.dispatch(AppAction(type: .MerchantLogout()))
})
}
It opens the browser again and shows that page. The user is successfully logged out (the cookies are reset, etc) but I would like the browser to just close instead of showing the sign in form again. Signing in through that form does not call my OAuth callback. Instead it just signs them in and sends them to the square dashboard.
What's the proper way of signing out the user using an in app SFSafariViewController + OAuth?
Eventually I just ended up doing this:
#IBAction func signOutButtonPressed(_ sender: AnyObject) {
let svc = SFSafariViewController(url: URL(string: "https://squareup.com/logout")!)
self.present(svc, animated: true, completion: {
appStore.dispatch(AppAction(type: .MerchantLogout()))
self.dismiss(animated: false, completion: nil)
})
}

ios9 - Swift 2.1 - SFSafariViewController

I'm looking to use the SFSafariViewController and have it automatically load a website when the app is opened. Is this possible?
What I have so far (brand new single ios app):
// ViewController.swift
let urlString = "https://stackoverflow.com"
#IBAction func launchSFSafariViewController(sender: AnyObject) {
if let url = NSURL(string: urlString) {
let vc = SFSafariViewController(URL: url, entersReaderIfAvailable: true)
vc.delegate = self
presentViewController(vc, animated: true, completion: nil)
}
}
How do I connect the action to the main view controller via the storyboard? All the articles I see only discuss connecting a button to an action.
Implement viewDidAppear to perform the presentation. (You will need to use a Bool flag, though, to make sure this doesn't happen when you dismiss the presented view controller and viewDidAppear is called again!)

Resources