IOS: Code to present login screen modally

user1904273

I want to password protect app with login screen (and join screen for first use). Some answers on SO suggest testing if user is logged in in viewdidappear of initial screen and, if not logged in, presenting the login screen modally.

I tried this but code is not working. Does anyone know up to date code for presenting a modal view controller? Note I created login screen in storyboard and have given it storyboard id "login".

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    //if not logged in, modally present login screen here.

    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"loggedIn"]) {
        // go to login screen
        NSLog(@"not logged in");//this fires so logic is ok
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"login"];//this line gives warning it is not being used
    } else {
        // go to main screen
    }
} 
/*perhaps I should call this somewhere?

- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
*/
Ali Riahipour

Credit to @rdelmar comment, You have to presentViewController:animated:completion: (presentModalViewController:animated: that ivc.

- (void)viewDidAppear:(BOOL)animated
{
   [super viewDidAppear:animated];
   //if not logged in, modally present login screen here.

   if(![[NSUserDefaults standardUserDefaults] boolForKey:@"loggedIn"]) {
       // go to login screen
       NSLog(@"not logged in");//this fires so logic is ok
       UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
       UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"login"];//LOOK AT NEXT LINE
       [self presentViewController:ivc animated:YES completion:nil]; //THIS LINE IS MISSING.
  } else {
    // go to main screen
  }
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Issue with presenting custom size ViewController modally in ios 8 with keyboard

분류에서Dev

Black screen instead of login screen

분류에서Dev

Kubuntu black screen after login

분류에서Dev

After login, nothing but a black screen

분류에서Dev

Unable to run code in screen

분류에서Dev

code has no resources but signature indicates they must be present

분류에서Dev

UIAlertController code runs, but doesn't present an alert

분류에서Dev

How to make the lock screen look like the login screen?

분류에서Dev

Cannot login into GNOME, kicking me back to login screen

분류에서Dev

How to show on login screen the last login informations (Windows 10)?

분류에서Dev

Ubuntu 18.04 keyboard and mouse not working at login screen

분류에서Dev

kubuntu 16.04 SDDM login screen hangs

분류에서Dev

How to return the login screen of the original unity ubuntu?

분류에서Dev

How to enable numlock at boot time for login screen?

분류에서Dev

How to disable sleep/suspend at login screen?

분류에서Dev

How to change the login screen keyboard layout?

분류에서Dev

14.04 unity does not start after login screen

분류에서Dev

It Automatically select last username on login screen

분류에서Dev

How to display IP at login screen in Arch Linux

분류에서Dev

rotated monitor. login screen needs rotation

분류에서Dev

How to execute a script before login screen?

분류에서Dev

How login a user on desktop screen using ssh

분류에서Dev

Unity keeps crashing back into login screen

분류에서Dev

How can I take a screenshot of the login screen?

분류에서Dev

Default login screen missing, how to revert?

분류에서Dev

Ubuntu Screen rotation of 90° after successful login

분류에서Dev

Cannot change login screen background in 18.10

분류에서Dev

Creating a Login by linking login code with a java Gui

분류에서Dev

iOS Launch Screen Animation Time

Related 관련 기사

  1. 1

    Issue with presenting custom size ViewController modally in ios 8 with keyboard

  2. 2

    Black screen instead of login screen

  3. 3

    Kubuntu black screen after login

  4. 4

    After login, nothing but a black screen

  5. 5

    Unable to run code in screen

  6. 6

    code has no resources but signature indicates they must be present

  7. 7

    UIAlertController code runs, but doesn't present an alert

  8. 8

    How to make the lock screen look like the login screen?

  9. 9

    Cannot login into GNOME, kicking me back to login screen

  10. 10

    How to show on login screen the last login informations (Windows 10)?

  11. 11

    Ubuntu 18.04 keyboard and mouse not working at login screen

  12. 12

    kubuntu 16.04 SDDM login screen hangs

  13. 13

    How to return the login screen of the original unity ubuntu?

  14. 14

    How to enable numlock at boot time for login screen?

  15. 15

    How to disable sleep/suspend at login screen?

  16. 16

    How to change the login screen keyboard layout?

  17. 17

    14.04 unity does not start after login screen

  18. 18

    It Automatically select last username on login screen

  19. 19

    How to display IP at login screen in Arch Linux

  20. 20

    rotated monitor. login screen needs rotation

  21. 21

    How to execute a script before login screen?

  22. 22

    How login a user on desktop screen using ssh

  23. 23

    Unity keeps crashing back into login screen

  24. 24

    How can I take a screenshot of the login screen?

  25. 25

    Default login screen missing, how to revert?

  26. 26

    Ubuntu Screen rotation of 90° after successful login

  27. 27

    Cannot change login screen background in 18.10

  28. 28

    Creating a Login by linking login code with a java Gui

  29. 29

    iOS Launch Screen Animation Time

뜨겁다태그

보관