Alyafai
Alyafai

Reputation: 45

Why is my scene activating even though the canActivateForTargetContentIdentifierPredicate is false

  let mainSceneTargetContentIdentifier = "com.apple.gallery.mainIdentifier"

var window: UIWindow?

// MARK: - UIWindowSceneDelegate

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    print("willConnectTo") //3
    
    if let userActivity = connectionOptions.userActivities.first ?? session.stateRestorationActivity {
        if !configure(window: window, with: userActivity) {
            Swift.debugPrint("Failed to restore from \(userActivity)")
        }
    }
    // The 'window' property will automatically be loaded with the storyboard's initial view controller.
    
    // Set the activation predicates, which operate on the 'targetContentIdentifier'.
    let conditions = scene.activationConditions
    let prefsPredicate = NSPredicate(format: "self == %@", mainSceneTargetContentIdentifier)
    // The main predicate, which expresses to the system what kind of content the scene can display.
    conditions.canActivateForTargetContentIdentifierPredicate = prefsPredicate
    // The secondary predicate, which expresses to the system that this scene is especially interested in a particular kind of content.
    conditions.prefersToActivateForTargetContentIdentifierPredicate = prefsPredicate
}

this is from

apple WWDC 2019 session 212: Introducing Multiple Windows on iPad

From my understanding of the code, the value of targetContentIdentifier is com.apple.gallery.openDetail. and the value of mainSceneTargetContentIdentifier is com.apple.gallery.mainIdentifier so when comparing targetContentIdentifier and mainSceneTargetContentIdentifier in NSPredicate(format: "self == %@", mainSceneTargetContentIdentifier) it return false because obviously the two strings don't match. however, the scene gets activated anyway. for testing purposes, I initialized an NSPredicated(value:false) and I assigned it to the scene conditions and the scene got activated.

can some one explain why? according to the docs, it should work if the NSPredicate returns true and not vice versa

Upvotes: 0

Views: 29

Answers (0)

Related Questions