Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios4 处理挂起的应用程序的最佳方法是在其会话超时时_Ios4_Uialertview_Session Timeout_Uiactionsheet_Suspend - Fatal编程技术网

Ios4 处理挂起的应用程序的最佳方法是在其会话超时时

Ios4 处理挂起的应用程序的最佳方法是在其会话超时时,ios4,uialertview,session-timeout,uiactionsheet,suspend,Ios4,Uialertview,Session Timeout,Uiactionsheet,Suspend,我有一个包含登录会话的应用程序。当应用程序挂起(iOS 4)时,我保存当前时间,如果下一次应用程序激活是在挂起时间后15分钟内,我希望它恢复。否则,我希望它返回到登录屏幕,因为会话已过期 下面是我正在做的事情,我现在写下它来实现它: 在app delegate的applicationdidebecomeactive中,如果需要,我会检查时间并显示登录屏幕(modally)。但是问题是,如果应用程序在挂起时显示UIAlertView或UIActionSheet,则在我显示登录屏幕时,它不会自动将其

我有一个包含登录会话的应用程序。当应用程序挂起(iOS 4)时,我保存当前时间,如果下一次应用程序激活是在挂起时间后15分钟内,我希望它恢复。否则,我希望它返回到登录屏幕,因为会话已过期

下面是我正在做的事情,我现在写下它来实现它:

在app delegate的applicationdidebecomeactive中,如果需要,我会检查时间并显示登录屏幕(modally)。但是问题是,如果应用程序在挂起时显示UIAlertView或UIActionSheet,则在我显示登录屏幕时,它不会自动将其关闭。然后,UIAlertView或UIActionSheet将出现在它根本不属于的登录屏幕上。我知道我可以注册每个UIAlertView和UIActionSheet来监听ApplicationIDBecomeActive并在需要时关闭它们,但由于我的应用程序中到处都有它们,如果可以避免的话,这真的很方便

我想知道是否有一种方法可以消除所有活动视图,即使以模式显示另一个视图控制器,这些视图也会保留在屏幕上


或者在iOS 4中是否有更好的方法来处理会话超时?

我找到了一种不用通知的方法(尽管通知并不像看上去那么难): 我向每个显示UIAlertView的类添加了一个iVar,以保存当前显示的AlertView。在AlertView的定义中:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle: ....
[alert show];
self.alertView = alert;
[alert release];
并在AlertView关闭时清理iVar:

- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)index {
    // code goes here
    self.alertView = nil;
}
然后在
-(void)视图中将消失:(BOOL)动画
-(void)dealoc
(视情况而定)我添加了:

UIActionSheet也可以这样做。希望这有帮助

如果您有更好的解决方案,请告诉我

    [self.alertView dismissWithClickedButtonIndex:0 animated:YES];