2016-01-22 36 views
0

在我正在處理的應用程序中,我讓用戶使用密碼作爲其TouchID的備份。顯然,出於安全原因,這個密碼應該有某種形式的類似於iPhone鎖定屏幕的「超時」。錯誤密碼的iOS超時

什麼是最好的方法來實現這一目標?

我最初的想法是保存用戶最後一次不正確的嘗試,並進行檢查,看看它是否超過當前日期的x分鐘數。

我認爲這將在實踐中起作用,然而將它綁定到系統時鐘絕對不是最安全的方法。

任何有關此事的幫助將不勝感激。

回答

1

我已經在幾個應用程序中實現了這種形式。我通常所做的就是使用一個計時器,該計時器在用戶與應用程序交互時開始(並且如果存在則取消前一個計時器)。當時間用完時,則運行超時方法。
是這樣的:

- (void)pressedButton:(UIButton *)button { 
    // record button press 

    [self scheduleInteractionTimer]; 
} 

- (void)scheduleInteractionTimer { 
    if (_timeoutTimer) { 
    [_timeoutTimer invalidate]; 
    } 
    _timeoutTimer = [NSTimer timerWithTimeInterval:timeoutTime target:self selector:@selector(timeoutTripped) userInfo:nil repeats:NO]; 
    _timeoutTimer.tolerance = 5.0; // optional 
    [[NSRunLoop mainRunLoop] addTimer:_timeoutTimer forMode:NSRunLoopCommonModes]; 
} 

- (void)timeoutTripped { 
    // whatever should be done for a timeout... 
} 

你肯定可以配合-scheduleInteractionTimer不正確的反應或其他任何你想。

編輯:我也建議解除應用程序進入後臺時的密碼視圖。

乾杯

安東尼