会话验证/管理最佳实践?

时间:2017-06-07 13:04:58

标签: ios swift3

我正在使用Swift3开发IOS应用程序。一旦用户通过身份验证,我就会收到sessionToken。我想检查用户是否登录,或者每次用户将应用程序放在后台并再次打开时。在哪里办理这些检查?我应该使用AppDelegate.swift重写方法来验证这些东西吗?或者它应该在其他地方完成?

另外,我想知道如何处理用户的无效性。如果用户未处于活动状态,则如何自动注销(未检测到触摸事件,无论是在应用程序的活动状态还是后台状态)。

申请结构: 1. LoginViewController(默认登陆界面) 2. HomeScreen-> 2.1 UserList

2 个答案:

答案 0 :(得分:0)

您可以看看以下两种方法,

Const ROW_COUNT As Long = 42
Const COL_COUNT As Long = 8
Const START_ROW As Long = 2
Dim refArray As Variant, testArray As Variant
Dim rowSize As Long, r As Long, c As Long, i As Long
Dim cell As Range, yesRng As Range, noRng As Range

'Read data into arrays
With Sheet1
    'Find last row of data
    rowSize = .Cells(.Rows.Count, "B").End(xlUp).Row
    'Adjust last row to be multiple of 42
    rowSize = Int((rowSize - START_ROW) / ROW_COUNT) * ROW_COUNT

    refArray = .Cells(START_ROW, "B").Resize(ROW_COUNT, COL_COUNT).Value2
    testArray = .Cells(START_ROW + ROW_COUNT, "B").Resize(rowSize, COL_COUNT).Value2
End With

'Compare test array with reference array
i = 1 'refArray row index
For r = 1 To UBound(testArray, 1)
    For c = 1 To UBound(testArray, 2)
        Set cell = Sheet1.Cells(r + START_ROW + ROW_COUNT - 1, c + 1)
        If testArray(r, c) = refArray(i, c) Then
            'It's a match so add to yes range
            If yesRng Is Nothing Then
                Set yesRng = cell
            Else
                Set yesRng = Union(yesRng, cell)
            End If
        Else
            'It's a miss so add to no range
            If noRng Is Nothing Then
                Set noRng = cell
            Else
                Set noRng = Union(noRng, cell)
            End If
        End If
    Next
    'Increment ref row index or set back to 1 if at 42
    i = IIf(i < ROW_COUNT, i + 1, 1)
Next

'Colour the ranges
If Not yesRng Is Nothing Then yesRng.Interior.Color = vbGreen
If Not noRng Is Nothing Then noRng.Interior.Color = vbRed

答案 1 :(得分:0)

正如Lion所说,你可以处理这两个功能。完成您请求的用例。

案例1:当应用程序被终止时。处理

    func applicationWillTerminate(_ application: UIApplication) {
}

案例2:

 func applicationWillResignActive(_ application: UIApplication) {

      //Start a timer to invoke a method and handle your session clear and local notification to inform user in that method.

    }

处使计时器无效
func applicationDidBecomeActive(_ application: UIApplication) {
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
}

希望这有帮助。