密码保护 iPhone 应用程序
我正在启动一个新应用程序,我想知道如何需要密码才能打开它。
我正在考虑在应用程序委托实现文件的应用程序 didFinishLaunchingWithOptions
方法中使用 UIActionSheet
,但我不确定如何执行此操作。不过我会继续努力。
找到此视频,看起来很有帮助。
现在,我的 UIActionSheet
会弹出并显示“输入密码”,并且正在尝试弄清楚如何将键盘添加到操作表中。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是我找到的一些示例。
注:https://
Here are some samples I found.
Note: https://
我认为使用完整的 UIViewController 实例而不是 UIActionSheet 可能会更好。将键盘行为添加到操作表中即使不是不可能,也是很困难的。
如果您创建
UIViewController
子类,则可以让您的应用程序委托将其呈现在-application:didFinishLaunchingWithOptions:
中。假设您在主界面中使用某种UIViewController
或UINaviagtionController
,您可以使用UIViewController
在启动时以模态方式呈现密码视图控制器-presentModalViewController:animated:
。拥有密码视图控制器后,您需要添加一个
UITextField
来输入密码。使文本字段成为firstResponder
(通过调用becomeFirstResponder
),这将导致显示键盘。您可能还需要在文本字段上设置keyboardAppearance
属性来控制键盘的显示方式,例如,如果您想要限制为数字 PIN 与完整密码。设置 secureTextEntry 属性也可能有助于防止显示实际密码。有关这两个选项,请参阅UITextField
上的UITextInputTraits
协议。为了确保应用程序的安全,您将创建密码视图控制器,以便它除了“提交”或“登录”类型按钮之外没有任何按钮或导航选项。如果用户输入正确的密码,您将关闭模态视图控制器并让他们进入。如果他们不知道密码,他们唯一的选择就是点击“主页”按钮退出您的应用程序,因为他们将无法继续超越模态视图控制器。
I think you may have better luck using a full
UIViewController
instance instead of aUIActionSheet
. Adding keyboard behavior to an action sheet will be difficult if not impossible.If you create a
UIViewController
subclass, you can make your application delegate present it in-application:didFinishLaunchingWithOptions:
. Assuming you're using some sort ofUIViewController
orUINaviagtionController
for your main interface, you could have the password view controller presented modally at startup usingUIViewController
-presentModalViewController:animated:
.Once you have your password view controller, you'll need to add a
UITextField
for password entry. Make the text field becomefirstResponder
(by callingbecomeFirstResponder
on it), and that will cause the keyboard to be displayed. You may also want to set thekeyboardAppearance
property 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 thesecureTextEntry
property may also be desirable to prevent the actual password from being display. See theUITextInputTraits
protocol onUITextField
for both of those options.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.
认为存储库 http://github.com/lashad/PTPasscodeViewController 对于访问此页面的人可能有用。
Thought the repo http://github.com/lashad/PTPasscodeViewController could be useful for someone visit this page.
UIAlertView
怎么样?但我不知道该应用程序是否会被拒绝。一些人说是,其他人说不是。不知道过去的事情有没有改变。以下是一些链接:
http://junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html
iPhone 上 UIAlertView 中的 UITextField - 如何使其响应?
http://iphone-dev-tips.alterplay.com/2009/ 12/用户名和密码-uitextfields-in.html
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/
大多数链接的作用相同,它们都使用
CGAffineTransformMakeTranslation
。有人说iOS 4不需要这个。而且有时会出现问题。没有尝试,因为我不想被拒绝......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.Here are some links:
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?
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://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 ...