ios - How to detect privacy permission changes (Camera access for example) -
we've been there. want take photos within app, or access photos, microphone, contacts, etc... first ios must prompt user permission. in many cases user deny access.
if app detects user has denied access, can navigate user app's privacy settings this:
[[uiapplication sharedapplication] openurl:[nsurl urlwithstring:uiapplicationopensettingsurlstring]];
handy. however....
i've noticed if convince user toggle switch on, app not detect changes.
consider code. user prompted permission access camera (this shows first time app run). suppose user denied permission. next decide did want enable camera access after all. no problem. user taps on button brings privacy panel. user changes switch allow access. user switches app. block fires uiapplicationdidbecomeactivenotification reads permission again. not reflect user's changes (still reads denied).
if app purged memory , run again, read state.
not permissions behave way. instance corelocation seems detect user's changes. i've found way detect changes notifications. contacts, calendars, camera, microphone, core motion (and more) changes not detected until app terminated , run again.
any ideas?
#import "viewcontroller.h" @import avfoundation; @interface viewcontroller () @end @implementation viewcontroller - (void)viewdidload { [super viewdidload]; [[nsnotificationcenter defaultcenter] addobserverforname:uiapplicationdidbecomeactivenotification object:nil queue:[nsoperationqueue mainqueue] usingblock:^(nsnotification *note) { [self printpermission]; }]; [avcapturedevice requestaccessformediatype:avmediatypevideo completionhandler:^(bool granted) { [self printpermission]; }]; } -(void)printpermission{ dispatch_async(dispatch_get_main_queue(), ^{ avauthorizationstatus status = [avcapturedevice authorizationstatusformediatype:avmediatypevideo]; if(status == avauthorizationstatusnotdetermined){ nslog(@"vwwpermissionstatusnotdetermined"); self.view.backgroundcolor = [uicolor whitecolor]; } else if(status == avauthorizationstatusauthorized){ nslog(@"vwwpermissionstatusauthorized"); self.view.backgroundcolor = [uicolor greencolor]; } else if(status == avauthorizationstatusdenied) { nslog(@"vwwpermissionstatusdenied"); self.view.backgroundcolor = [uicolor redcolor]; } else if(status == avauthorizationstatusrestricted) { nslog(@"vwwpermissionstatusrestricted"); self.view.backgroundcolor = [uicolor redcolor]; } }); } - (ibaction)buttonaction:(id)sender { [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:uiapplicationopensettingsurlstring]]; } @end
so, turned out bug related ios 9b1.
permission detection works fine on ios 8.
i did learn need check permission on main queue. if that, reflect updates.
Comments
Post a Comment