gpt4 book ai didi

ios - 将应用程序首次打开时的警报设置为弹出/让用户在应用程序密码中设置

转载 作者:行者123 更新时间:2023-11-29 12:03:53 25 4
gpt4 key购买 nike

无法在用户首次打开应用程序时弹出警报。我希望每个 View 都有不同的提醒,以指导用户完成首次运行。

我不知道我错过了什么。浏览了网站上的各种帖子,但无法弄清楚。

ViewController.h

    #import <UIKit/UIKit.h>



@interface ViewController : UIViewController <UINavigationControllerDelegate,UIImagePickerControllerDelegate> {

}

@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end



@implementation ViewController


- (void)viewdDidLoad {
[super viewDidLoad];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

if(![[NSUserDefaults standardUserDefaults] boolForKey:@"AlreadyRan"] )
{
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"The Key"
message:@"Press The Key Hole"
preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];

}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];

}];

[alert addAction:ok];
[alert addAction:cancel];

[self presentViewController:alert animated:YES completion:nil];

[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"AlreadyRan"];
}
return 0;
}



@end

同样在另一个 View Controller 上,我希望用户能够在应用程序首次运行时通过警报弹出窗口设置密码。这是我将密码设置为标准密码的代码。密码不需要存储到钥匙串(keychain)中,它不是那种我只希望应用程序将其保存在本地的应用程序。

PassViewController.m

- (IBAction)enterPassword {
NSString *passwordString = [NSString stringWithFormat:@"1234"];

if ([passwordField.text isEqualToString:passwordString]) {
//Password is Correct
NSString * storyboardName = @"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"PhotoView"];
[self presentViewController:vc animated:YES completion:nil];

}


else {
//Password is wrong
[self dismissViewControllerAnimated:YES completion: nil];

}
}

最佳答案

你已经在 View Controller 中实现了(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions,但实际上这个方法属于UIApplicationDelegate 协议(protocol)(通常位于您的 AppDelegate.m 中)。

所以iOS永远不会调用这个方法。

我认为您正在寻找的是 -(void) viewDidAppear: (BOOL) animated { ... }。当 View Controller 出现在屏幕上时,它会被调用。所以你的实现看起来像

-(void) viewDidAppear: (BOOL) animated {
[super viewDidAppear: animated];
/* All your other code that used to be in didFinishLaunchingWithOptions */
}

关于ios - 将应用程序首次打开时的警报设置为弹出/让用户在应用程序密码中设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35761695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com