Skip to content
This repository has been archived by the owner on Feb 27, 2019. It is now read-only.

Crash on Contacts Authorization #127

Closed
winkelsdorf opened this issue Nov 11, 2015 · 14 comments
Closed

Crash on Contacts Authorization #127

winkelsdorf opened this issue Nov 11, 2015 · 14 comments
Labels
Milestone

Comments

@winkelsdorf
Copy link

Checked out accc3c4 and tested the Demo. It crashes when Authorizing the Contacts (first I denied them, then opening the Settings via the Link).

Xcode 7.1, iOS 9.1 Simulator used.

2015-11-11 12:55:17.575 PermissionScope-example[69624:5304177] Presenting view controllers on detached view controllers is discouraged <PermissionScope.PermissionScope: 0x7f97e3815c00>.
thing was cancelled
2015-11-11 12:55:29.106 PermissionScope-example[69624:5304177] Presenting view controllers on detached view controllers is discouraged <PermissionScope.PermissionScope: 0x7f97e3815c00>.
2015-11-11 12:55:31.089 PermissionScope-example[69624:5304177] _BSMachError: (os/kern) invalid capability (20)
2015-11-11 12:55:31.089 PermissionScope-example[69624:5308632] _BSMachError: (os/kern) invalid name (15)
got results [Notifications Authorized]
got results [Notifications Authorized]
got results [Notifications Authorized]
got results [Notifications Authorized]
thing was cancelled
got results [Contacts Unknown, Notifications Authorized, LocationInUse Unknown]
got results [Contacts Unknown, Notifications Authorized, LocationInUse Unauthorized]
2015-11-11 12:56:23.453 PermissionScope-example[69624:5304177] Presenting view controllers on detached view controllers is discouraged <PermissionScope.PermissionScope: 0x7f97e2037600>.
2015-11-11 12:56:27.176 PermissionScope-example[69624:5304177] Presenting view controllers on detached view controllers is discouraged <PermissionScope.PermissionScope: 0x7f97e2037600>.
2015-11-11 12:56:28.779 PermissionScope-example[69624:5304177] _BSMachError: (os/kern) invalid capability (20)
2015-11-11 12:56:28.779 PermissionScope-example[69624:5304177] _BSMachError: (os/kern) invalid name (15)
got results [Contacts Unknown, Notifications Authorized, LocationInUse Authorized]
got results [Contacts Unknown, Notifications Authorized, LocationInUse Authorized]
got results [Contacts Unauthorized, Notifications Authorized, LocationInUse Authorized]
2015-11-11 12:56:49.765 PermissionScope-example[69624:5304177] Presenting view controllers on detached view controllers is discouraged <PermissionScope.PermissionScope: 0x7f97e2037600>.
2015-11-11 12:56:51.851 PermissionScope-example[69624:5304177] _BSMachError: (os/kern) invalid capability (20)
2015-11-11 12:56:51.851 PermissionScope-example[69624:5304177] _BSMachError: (os/kern) invalid name (15)
got results [Contacts Unauthorized, Notifications Authorized, LocationInUse Authorized]
thing was cancelled
2015-11-11 12:58:14.566 PermissionScope-example[69624:5304177] Presenting view controllers on detached view controllers is discouraged <PermissionScope.PermissionScope: 0x7f97e2037600>.
2015-11-11 12:58:16.672 PermissionScope-example[69624:5304177] _BSMachError: (os/kern) invalid capability (20)
2015-11-11 12:58:16.672 PermissionScope-example[69624:5304177] _BSMachError: (os/kern) invalid name (15)
(lldb) 
@bre7 bre7 added the bug label Nov 11, 2015
@nickoneill
Copy link
Owner

Thanks @winkelsdorf, I'll take a look at this. Possibly related to the new iOS 9 Contacts framework that was pulled in recently.

@winkelsdorf
Copy link
Author

@nickoneill You're welcome! Sorry that I didn't had the time to fix/create a PR before leaving the office today. Yes, the new Contacts framework is likely the reason for the crash.

Did you also notice the detached view controller warning at the very beginning of the console output? I know why but wondering if there is a better way to present the Dialog View.. Having a look at it later this week..

Cheers

@nickoneill
Copy link
Owner

Yep, if you set the viewControllerForAlerts property to the presenting view controller, the dialog is presented in the proper hierarchy without the warning. Perhaps we should issue our own warning about this with the proposed solution.

@winkelsdorf
Copy link
Author

Excellent idea, I would say just issue a warning and point to the best practice / correct way.

Thanks for the great implementation, I first read about this approach at NatashaTheRobot's Blog some month ago (iirc) and had this implementation on my list too :)

@nickoneill nickoneill added this to the 1.0.2 milestone Nov 28, 2015
@nickoneill
Copy link
Owner

@winkelsdorf I'm just getting around to finding a repro for this now. Is this the case where it crashes when you toggle the settings switch? If so, that's just how iOS works with the contacts permissions (with both iOS 8 and 9) - you get killed when your contacts permission changes.

@nickoneill
Copy link
Owner

I just tested viewControllerForAlerts as well and it actually presents behind the pscope window. Obviously not what we wanted. Did you see the correct behavior after that fix @winkelsdorf?

Just for reference: we manually insert the pscope view into the top of the window view hierarchy which is why presenting on the app view controller shows behind the pscope view. Presenting from the pscope view controller gives the correct behavior but is 'discouraged' because the pscope controller isn't actually on the view controller stack. Potential fix: convert showing pscope to a modal view controller that's shown with presentViewController... with the UIModalPresentationOverCurrentContext style.

Thoughts @bre7 / @winzig (as the original viewControllerForAlerts author)?

This was referenced Dec 7, 2015
@denismars
Copy link

I can repo the same crash issue with both toggling the Contacts and the Bluetooth switches in the Settings. Changing the Notifications and Locations settings did not crash it - only the toggle switches seem to crash or terminate the app.

But before it crashes I see this error when the transition to the Settings app starts:
_BSMachError: (os/kern) invalid capability (20)
_BSMachError: (os/kern) invalid name (15)

Not sure if this is useful to help debug this.

@nickoneill
Copy link
Owner

Hey @denismars, that crash isn't something we can control. Any app will crash when toggling the Contacts permissions.

@nickoneill nickoneill modified the milestones: 1.1, 1.0.2 Jan 14, 2016
@nickoneill
Copy link
Owner

At this point I don't believe viewControllerForAlerts works as expected. I'm planning on removing it in 1.1 since no one else has weighed in.

@winzig
Copy link
Contributor

winzig commented Jan 14, 2016

Sorry, I just saw this thread now. I've not had any problems using viewControllerForAlerts, I'm reading through this discussion now and am not clear on how it pertains to the crash related to Contacts authorization? If you remove viewControllerForAlerts, how will we be able to call the request* methods directly, since if PS needs to show a view, it won't be able to put it into the hierarchy correctly, right?

@nickoneill
Copy link
Owner

Hey @winzig, It's not related to the Contacts crash, you can safely ignore.

Here's what I was seeing when I set viewControllerForAlerts: the pscope UI showed up OK, but then clicking on a permission showed the native permissions alert behind the pscope window.

Normally these native alerts are presented on top of the pscope view which works, despite giving a "don't present view controllers on deteached view controllers" warning (because I added the pscope view manually to the current view controller, not through the proper presentation).

I think the correct thing to do here is modify pscope so that it's a view controller presented modally with that setting (the name is on the tip of my tongue...) that allows us to see to the view controller underneath, so it looks like the current implementation. We can customize the presentation with the animated transitioning API if necessary.

@winzig
Copy link
Contributor

winzig commented Jan 14, 2016

Strange! I hadn't seen that behavior in our app (iOS 8/9) and we're doing mostly the direct request* calls. I have always felt the way I had proposed (setting that vc directly) felt a bit hacky, but seemed like a different solution would require more of a re-architecting of how this project works than I would have been comfortable suggesting. ;-)

@nickoneill
Copy link
Owner

For clarity, I'm going to resolve this and create a new issue. I am fascinated that you haven't seen the same thing @winzig, but I'm sure I reviewed it when you made the original PR and I didn't see any weirdness then either.

Still, avoiding this in the first place is the way to go!

@winkelsdorf
Copy link
Author

@nickoneill Sorry for the late reply. I'll implement this into a test project asap and have a look into it too. But from my point of view #148 is the safest thing to do.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants