Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASAuthorizationAppleIDButton not responding to touchUpInside events

I've experienced strange bug in Latest Xcode 11.0 My code:

let button = ASAuthorizationAppleIDButton(type: .default, style: .black)
button.translatesAutoresizingMaskIntoConstraints = false
button.cornerRadius = 10
button.addTarget(self, action: #selector(appleSignInButtonSelected(_:)), for: .touchUpInside)

Selector never called, but if I change event to touchDown, everything works.

like image 263
tereks Avatar asked Sep 26 '19 10:09

tereks


4 Answers

I think it is apple bug. Use touchDown instead of touchUpInside.

like image 123
erdikanik Avatar answered Nov 19 '22 13:11

erdikanik


I've experienced same issue. In my case I've had UITapGestureRecognizer attached to main view of the view controller. Setting property cancelsTouchesInView of the gesture recognizer to false helped.

like image 36
Slavo Avatar answered Nov 19 '22 15:11

Slavo


I found out the best way to do this is to just use UITapGestureRecognizer

let button = ASAuthorizationAppleIDButton()
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleAuthorizationAppleIDButtonPress))
button.addGestureRecognizer(tapGesture)

Using addTarget(_:action:for:) with .touchDown would require the user to long tap the button (~1s longer than normal) before action is detected which is unusual.

Apple even rejected my app submission because "tapping the Sign in with Apple button did not produce any actions".

I recommend just using a tap gesture recognizer to avoid any issues.

like image 2
ejboi Avatar answered Nov 19 '22 13:11

ejboi


I found that the ASAuthorizationAppleIDButton did not receive any tap gestures at all (down or upInside) if there was a layout problem with its parent.

In my case, I had left out a constraint in one of the parent views, which caused the ASAuthorizationAppleIDButton to be outside the frame of the parent view.

This was in a storyboard, so there was a red arrow and warning about it, but I had missed that initially. I found this by debugging the view hierarchy and noting the position of each of the ancestor views up the tree.

The fix is to ensure that there are constraints to keep the ASAuthorizationAppleIDButton within the frame of its ancestors.

like image 1
Robin Daugherty Avatar answered Nov 19 '22 15:11

Robin Daugherty