nickoneill / PermissionScope

Intelligent iOS permissions UI and unified API
MIT License
4.85k stars 507 forks source link

Bug with MotionPermission #170

Open ogezue opened 8 years ago

ogezue commented 8 years ago

I'm trying to use PermissionScope with Objective C and configure it to request for Motion, Location and Notification. I get a non deteministic behavior.

Sometimes PermissionScope is displayed after I open the UI a second time. Sometimes I'm in an endless loop of private func triggerMotionStatusUpdate() {} that gets called in self.permissionScope = [[PermissionScope alloc] init];. This results in a white screen and the iOS permission alert is visible when quitting the app.

Is the code below not correct or is this a bug in PermissionScope?

- (void)showPermissions{
   self.permissionScope = nil;
   self.permissionScope = [[PermissionScope alloc] init];
   self.permissionScope.headerLabel.text = NSLocalizedString(@"permission_header",nil);
   self.permissionScope.bodyLabel.text = NSLocalizedString(@"permission_body",nil);
   [self.permissionScope.closeButton setTitle:NSLocalizedString(@"Close",nil) forState:UIControlStateNormal];

   // Set up permissions
   [self.permissionScope addPermission:[[LocationWhileInUsePermission alloc] init] message:NSLocalizedString(@"LocationWhileInUsePermissionMessage",nil)];
       [self.permissionScope addPermission:[[MotionPermission alloc] init] message:NSLocalizedString(@"MotionPermissionMessage",nil)];
       [self.permissionScope addPermission:[[NotificationsPermission alloc] initWithNotificationCategories:nil] message:NSLocalizedString(@"NotificationsPermissionMessage",nil)];

   // Styles
   [self.permissionScope setLabelFont:[Styling fontDescription]];
   [self.permissionScope setButtonFont:[Styling fontDescription]];
   [self.permissionScope.headerLabel setFont:[Styling fontValue]];
   [self.permissionScope.bodyLabel setFont:[Styling fontDescription]];
   [self.permissionScope.closeButton setFrame:CGRectMake(0, 0, 100, 20)];
   [self.permissionScope setCloseOffset:CGSizeMake(-20, 0)];

   [self.permissionScope show:^(BOOL finished, NSArray<PermissionResult ​*> *​ _Nonnull results) {
       NSLog(@"show");
   } cancelled:^(NSArray<PermissionResult ​*>*​ _Nonnull results) {
       NSLog(@"cancelled");
   }];
}
nickoneill commented 8 years ago

Possibly a similar case to #147? Looks like you're doing things correctly so likely some issue with the async motion request.