在iPhone中单击主页按钮显示警报消息

时间:2011-09-06 05:04:02

标签: iphone uialertview

在Iphone中,我必须立即显示警告,如果用户立即点击主页按钮以表明“该过程将被停止并且他将丢失数据”。我必须尝试使用​​applicationWillResignActive和applicationDidEnterBackground.Can实现此操作。任何人帮助我如何实现这一目标?在主页按钮上显示此类警报消息是否合适

谢谢, Yogesh Chaudhari

1 个答案:

答案 0 :(得分:0)

Try this below code this will help you.

Its not really a way to quit the program, but a way to force people to quit.

UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:@"Hit Home Button to Exit" message:@"Tell em why they're quiting" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[anAlert show];

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   if (buttonIndex == 0) 
    {
        [[NSThread mainThread] exit]
    }
}