3

I process push notification at

application(_:didReceiveRemoteNotification:fetchCompletionHandler:)

method in AppDelegate.swift module

When application is active I show my own banner in application window:

if application.applicationState == .active {
    // create banner
    banner.show()
}

When application is in background iOS show system banner and my application receive info when application.applicationState has .background value. If user tapped the banner application receive data again but application.applicationState is .inactive - in this case I opens entity item that info was received in notification.

But when the device is locked with a password (ie requires code or fingerprint):

  • Application receive notification data only when user did tap the banner, not immediately as in just background mode (when device is not password-locked)
  • After unlock application state is still .background

How can I differ background state after password-unlocking and background without locking?

I did try set flags by processing

applicationDidBecomeActive(_ application: UIApplication)

and

applicationWillEnterForeground(_ application: UIApplication)

events but

application(_:didReceiveRemoteNotification:fetchCompletionHandler:)

calls earlier

General Failure
  • 2,421
  • 4
  • 23
  • 49

2 Answers2

2

You can identify whether the device is currently locked using the isProtectedDataAvailable property of UIApplication

let isUnlocked = UIApplication.shared.isProtectedDataAvailable

You can then use the combination of isUnlocked and applicationState to determine that you are in the background but that the device is locked and process accordingly.

Note that isProtectedDataAvailable will always return true if data protection isn't enabled on the device (e.g. no passcode is set).

Paulw11
  • 108,386
  • 14
  • 159
  • 186
0

I think below thread will solve your problem: How to differentiate between screen lock and home button press on iOS5?

I haven't tried it but people says its working perfectly fine and even no issue with app approval process.

torap
  • 656
  • 6
  • 15
  • That thread is about leaving application. And my question is about entering app. Can you specify what answer can help me differ when device was password-locked before user entered app? – General Failure Jan 09 '18 at 04:05