2

を使用してUILocalNotificationをスケジュールしていますがUIAlertView、これは問題なく機能します。ただし、ユーザーがしばらく (たとえば 1 分) 後に通知に応答しない場合は、「何かをする」必要があります。また、これを行うUIAlertView別の方法がある場合は、 a を使用する必要はありません。

4

1 に答える 1

0

UIAlertView を表示するとすぐに、NSTimer でタイマーを開始できます。タイマーが終了したら、必要な特定のアクションを実行できます。ユーザーが UIAlertView のボタンの 1 つをタップすると、タイマーが無効になります。

簡単なサンプル:

@interface AppDelegate : UIResponder <UIApplicationDelegate, UIAlertViewDelegate> {
    UIAlertView *alert;
    NSTimer *timer;
}

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    alert = [[UIAlertView alloc] initWithTitle:@"Test" message:@"test" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];

    timer = [NSTimer timerWithTimeInterval:4 target:self selector:@selector(timerTick:) userInfo:nil repeats:NO];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];

    return YES;
}

- (void)timerTick:(NSTimer*)timer
{
    [alert dismissWithClickedButtonIndex:-1 animated:YES];
}

- (void)alertViewCancel:(UIAlertView *)alertView
{
    [timer invalidate];
}

@end
于 2012-10-21T14:59:38.493 に答える