migrating project to comply with google sign in requirements for iOS - ios

I'm trying to get a google sign in button to work with my iOS app, but I'm getting this error here:
Cannot find 'presentingViewController' in scope
This is the code segment:
func handleSignInButton() {
GIDSignIn.sharedInstance.signIn(
with: signInConfig,
presenting: presentingViewController // this is the line with the error,
callback: GIDSignInCallback? = nil) { user, error in
guard let signInUser = user else {
// Inspect error
return
}
// If sign in succeeded, display the app's main content View.
}
}
I've been told I need to migrate the way I am signing in and I found this here:
https://developers.google.com/identity/sign-in/ios/quick-migration-guide
but I'm confused about this part here:
Manually connect GIDSignInButton to a method that calls signInWithConfiguration:presentingViewController:callback: using an IBAction or similar.
Can someone show me how to do this properly? I'm a iOS novice :)
Thanks!

Related

Callback issue with getSteam iOS sdk

I think something wrong with the iOS SDK of getStream. I m not getting any callback on following , unfollowing and checking if user is following someone.For all these three case callback is not coming.
Even in the sample app given by stream is not working for these case.
Below is the code from ProfileViewController from sample app.
Rest of the sample app working fine.
Url of the sample is : https://github.com/GetStream/swift-activity-feed
User.current?.isFollow(toTarget: flatFeedPresenter.flatFeed.feedId) { [weak self] in
button.isEnabled = true
if let error = $2 {
self?.showErrorAlert(error)
} else {
button.isSelected = $0
}
}
It was a bug, inside isFollow the user flat feed is deallocating after the request. Please check the new version v.1.0.11.

Why is admob consent form not loading on actual devices?

I am trying to implement Admob for my iOS app. The form loads on the Xcode simulator devices. I am located in the US, but I have used the following code to test that the Consent SDK is working for European users. When I use this with a simulator, the form and ads load.
PACConsentInformation.sharedInstance.debugIdentifiers = ["SPECIFIC_TO_MY_DEVICE"]
PACConsentInformation.sharedInstance.debugGeography = PACDebugGeography.EEA
The form does not load on my physical device with this configuration. The form also did not load when I used testflight to distribute a test version to a test user in the EU. Subsequently, the ads did not load on "European" devices.
When the form should load, I get an error from the below block of code. Also. I get the error WebKitDomain Error 101. My ATS settings are set up in the plist per the Admob documentation.
thisForm.load {(_ error: Error?) -> Void in
if let error = error {
print("Error loading form: \(error.localizedDescription)")
//I am getting the error here.
} else {
thisForm.present(from: self) { (error, userPrefersAdFree) in
print("in present handler")
if let error = error {
// Handle error.
print("error presenting: \(error.localizedDescription)")
} else if userPrefersAdFree {
//TODO: find a way to disable ads
} else {
// Check the user's consent choice.
//let status = PACConsentInformation.sharedInstance.consentStatus
}
}
}
Does anyone know what may be causing these errors with physical devices? I have tried with a real ad id and a test ad id.
Present consent form only if the following equals true
If requestLocationInEEAOrUnknown == true {
//present consent form
}
else {
//do whatever is needed
}

Stripe error : submitTokenToBackend error, unresolved identifier error

I am working on a stripe project on iOS. I followed the start guide on stripe website for a primary test.
For iOS app, their SDK had a built-in addCardViewController. So I just copy and paste the code to my ViewController file. However, now I am having an error which is, an unresolved identifier submitToBackEnd.
Can anyone tell me what the possible problem is?
Below I have added the code which I used:
func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreateToken token: STPToken, completion: #escaping STPErrorBlock) {
submitTokenToBackend(token, completion: { (error: Error?) in
if let error = error {
// Show error in add card view controller
completion(error)
}
else {
// Notify add card view controller that token creation was handled successfully
completion(nil)
// Dismiss add card view controller
dismiss(animated: true)
}
})
}
It's because you're missing the submitTokenToBackend function declaration. The Stripe documentation assumes you're writing it yourself. (it's mentioned here after the code block https://stripe.com/docs/mobile/ios/custom#stpapiclient--stpcardparams)
The implementation varies greatly depending on what you use to send requests from your App to your backend. It's not exactly the same but you can look at this part of the Standard Example to see how it roughly works:
https://github.com/stripe/stripe-ios/blob/master/Example/Standard%20Integration%20(Swift)/MyAPIClient.swift#L25

What's the iOS API for AWS Cognito User Pool Custom Authentication Flow?

Amazon docs docs outlines how its custom authentication flow works. But there are only passing mentions of iOS.
I have a working authentication system using AWS User Pools and its Custom Authentication Flow using Python Triggers and an iOS Swift app.
But there's a detail still troubling me - see comment after code.
In the AWSCognitoIdentityCustomAuthentication handler I've got this:
func getCustomChallengeDetails(_ authenticationInput: AWSCognitoIdentityCustomAuthenticationInput, customAuthCompletionSource: AWSTaskCompletionSource<AWSCognitoIdentityCustomChallengeDetails>) {
self.customAuthenticationCompletion = customAuthCompletionSource
if authenticationInput.challengeParameters.count > 0 {
DispatchQueue.main.async {
if let code = self.codeTextField.text {
let details = AWSCognitoIdentityCustomChallengeDetails(
challengeResponses: ["CODE" : code])
details.initialChallengeName = "CUSTOM_CHALLENGE"
customAuthCompletionSource.set(result: details)
}
}
}
func didCompleteStepWithError(_ error: Error?) {
// handling code
}
}
The first call of getCustomChallengeDetails() has an empty list for challengeParameters. The second call has a correctly populated challengeParameters
The method didCompleteStepWithError(_ error: Error?) misled me as I thought it only called when an error occurs but is in fact also called on success with error set to nil.
I also have a UIViewController that prompts the user for a CODE which they've been emailed by my server code. When the user submits the CODE I call this:
if let code = codeTextField.text {
let details = AWSCognitoIdentityCustomChallengeDetails(
challengeResponses: ["CODE" : code])
details.initialChallengeName = "CUSTOM_CHALLENGE"
self.customAuthenticationCompletion?.set(result: details)
DispatchQueue.main.async {
self.dismiss(animated: true, completion: nil)
}
}
This works. The server code will authenticate users who enter correct CODE values but deny those who submit an incorrect value for CODE.
But why the two customAuthenticationCompletion?.set(result: details) calls?
Can anyone say where I've taken a misstep?

Getting single Tweet with TwitterKit/Fabric authentication failure

I'm trying to retrieve a single tweet and show it in my application via the TWTRTweetView provided in the TwitterKit. I've followed this Fabric guide and ended up with following code.
import UIKit
import TwitterKit
class SingleTweetViewController: UIViewController{
#IBOutlet weak var plainView: UIView!
override func viewDidLoad(){
super.viewDidLoad()
Twitter.sharedInstance().logInGuestWithCompletion { session, error in
if let validSession = session {
Twitter.sharedInstance().APIClient.loadTweetWithID("4831830029115392") { tweet, error in
if let t = tweet {
let tweetView = TWTRTweetView(tweet: tweet)
tweetView.showActionButtons = true
self.plainView.addSubview(tweetView)
} else {
println("Failed to load Tweet: \(error?.localizedDescription)")
}
}
} else {
println("Unable to login as guest: \(error.localizedDescription)")
println(error?.localizedFailureReason)
}
}
}
The code generates these two errors due to authentication failure.
Unable to login as guest: Request failed: forbidden (403)
Optional("Twitter API error : Unable to verify your credentials (code 99)")
It is worth mentioning that the app successfully signs in to Twitter via the login button added following this guide. Does anyone have a clue how this error could be fixed? Am I missing some code here or is the issue related to Fabric?
You have to initialize Fabric before trying to use it which is what you're doing in your example code.
For the initialization, follow instructions from the Fabric documentation site. In essence, you have add the following lines to your app delegate (in addition to importing TwitterKit):
Twitter.sharedInstance().startWithConsumerKey("your_key", consumerSecret: "your_secret")
Fabric.with([Twitter.sharedInstance()])
Then copy and paste you're consumer key and secret from fabric.io. Fabric should automatically generate these for you.
I solved the problem using Fabric applications built in option "View tweet in application" found in the same menu as the "Add login button button" option. The Fabric application then inserts proper authentication keys into the Info.plist file. The code provided by Fabric application seems to do the same thing as the code given on Fabric docs but the result differs depending on which one you use. The two code samples look like this:
Code from Fabric docs:
Twitter.sharedInstance().logInGuestWithCompletion { session, error in
if let validSession = session {
Twitter.sharedInstance().APIClient.loadTweetWithID("20") { tweet, error in
if let t = tweet {
self.tweetView.configureWithTweet(t)
} else {
println("Failed to load Tweet: \(error.localizedDescription)")
}
}
} else {
println("Unable to login as guest: \(error.localizedDescription)")
}
}
Code from Fabric application:
Twitter.sharedInstance().logInGuestWithCompletion { (session, error) in
Twitter.sharedInstance().APIClient.loadTweetWithID("20") { (tweet, error) in
self.view.addSubview(TWTRTweetView(tweet: tweet))
}
}
Running the first code will give an authentication error while the second one will load a tweet without issues. The if-statement if let validSession = session returns a false and an authentication error occurs. I couldn't find what the validSession is exactly but it probably compares two different sets of keys or something similar.

Resources