ios 密码保护 iPhone 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2891138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:16:17  来源:igfitidea点击:

Password protect iPhone app

iosxcodeiphone-sdk-3.0password-protectionuiactionsheet

提问by Thomas

I'm starting a new app, and I'd like to know how to require a password to open it.

我正在启动一个新应用程序,我想知道如何要求输入密码才能打开它。

I was considering a UIActionSheetin the application didFinishLaunchingWithOptionsmethod of the app delegate implementation file, but am unsure how to go about doing so. I'm going to keep trying though.

我正在考虑UIActionSheet应用didFinishLaunchingWithOptions程序委托实现文件的应用程序方法中的一个,但我不确定如何去做。不过我会继续努力的。

Found this video, which seems pretty helpeful.

找到了这个视频,看起来很有帮助。

Now I've got my UIActionSheetto pop up displaying "Enter password," and am trying to figure how to add a keypad to the action sheet.

现在我有我UIActionSheet的弹出显示“输入密码”,并试图弄清楚如何将键盘添加到操作表中。

采纳答案by pendor

I think you may have better luck using a full UIViewControllerinstance instead of a UIActionSheet. Adding keyboard behavior to an action sheet will be difficult if not impossible.

我认为使用完整UIViewController实例而不是UIActionSheet. 如果不是不可能,将键盘行为添加到操作表将是困难的。

If you create a UIViewControllersubclass, you can make your application delegate present it in -application:didFinishLaunchingWithOptions:. Assuming you're using some sort of UIViewControlleror UINaviagtionControllerfor your main interface, you could have the password view controller presented modally at startup using UIViewController-presentModalViewController:animated:.

如果您创建一个UIViewController子类,您可以让您的应用程序委托以-application:didFinishLaunchingWithOptions:. 假设您正在使用某种UIViewControllerUINaviagtionController主界面,您可以在启动时使用UIViewController- 以模态方式显示密码视图控制器presentModalViewController:animated:

Once you have your password view controller, you'll need to add a UITextFieldfor password entry. Make the text field become firstResponder(by calling becomeFirstResponderon it), and that will cause the keyboard to be displayed. You may also want to set the keyboardAppearanceproperty on the text field to control how the keypad appears if for example you want to limit to a numeric PIN versus a full password. Setting the secureTextEntryproperty may also be desirable to prevent the actual password from being display. See the UITextInputTraitsprotocol on UITextFieldfor both of those options.

拥有密码视图控制器后,您需要添加一个UITextField密码条目。使文本字段变为firstResponder(通过调用becomeFirstResponder它),这将导致显示键盘。您可能还想设置keyboardAppearance文本字段上的属性来控制小键盘的显示方式,例如,如果您想限制为数字 PIN 码而不是完整密码。secureTextEntry也可能需要设置该属性以防止显示实际密码。请参阅UITextInputTraits有关UITextField这两个选项的协议。

In order to make the app secure, you would create your password view controller so that it has no buttons or navigation options other than a "Submit" or "Login" type button. If the user enters the correct password, you dismiss the modal view controller and let them in. If they don't know the password, their only choice is to tap the Home button to exit your application as they'd have no way to proceed beyond the modal view controller.

为了使应用程序安全,您将创建密码视图控制器,使其除了“提交”或“登录”类型按钮之外没有任何按钮或导航选项。如果用户输入了正确的密码,你关闭模态视图控制器并让他们进入。如果他们不知道密码,他们唯一的选择是点击主页按钮退出你的应用程序,因为他们无法继续超出模态视图控制器。

回答by palaniraja

Thought the repo http://github.com/lashad/PTPasscodeViewControllercould be useful for someone visit this page.

认为 repo http://github.com/lahad/PTPasscodeViewController可能对访问此页面的人有用。

回答by testing

What about a UIAlertView? But I don't know if the app gets rejected or not. A few say yes, the other no. Doesn't know if things changed in the past.

怎么样一个UIAlertView?但我不知道该应用程序是否被拒绝。有几个说是,另一个不是。不知道过去有没有变化。

Here are some links:

以下是一些链接:

http://junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html

http://junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html

UITextField in UIAlertView on iPhone - how to make it responsive?

iPhone 上 UIAlertView 中的 UITextField - 如何使其响应?

http://iphone-dev-tips.alterplay.com/2009/12/username-and-password-uitextfields-in.html

http://iphone-dev-tips.alterplay.com/2009/12/username-and-password-uitextfields-in.html

http://discussions.apple.com/thread.jspa?threadID=1674641&start=15&tstart=0

http://discussions.apple.com/thread.jspa?threadID=1674641&start=15&tstart=0

http://icodeblog.com/2009/11/09/iphone-coding-tutorial-inserting-a-uitextfield-in-a-uialertview/

http://icodeblog.com/2009/11/09/iphone-coding-tutorial-inserting-a-uitextfield-in-a-uialertview/

Most of the links do the same, they all use CGAffineTransformMakeTranslation. Someone stated that this isn't needed for iOS 4. And sometimes there are problems. Didn't tried it out, because I don't want to get rejected ...

大多数链接的作用相同,它们都使用CGAffineTransformMakeTranslation. 有人说iOS 4不需要这个。有时会出现问题。没有尝试过,因为我不想被拒绝......