Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when you return `false` from `application(_:, continue:​, restoration​Handler:​)`?

I have enabled Universal Links in my app. The corresponding delegate call to handle those links is

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    if canHandle(userAcitivity) {
        // Handle the universal link.
    }
    else {
        // ⛔️ Don't handle the universal link.
        return false
    }
}

No I wonder what exactly happens when I return false from this method. In the beginning I thought that Safari would simply open the link instead as it would without universal links enabled. However, I figured that my app is still opened and the documentation states:

If you do not implement this method or if your implementation returns false, iOS tries to create a document for your app to open using a URL.

What exactly does this mean?

What kind of document is created and how is my app notified about that?

like image 426
Mischa Avatar asked Mar 23 '17 13:03

Mischa


People also ask

What happen if I return false in Didfinishlaunchingwithoptions?

false if the app cannot handle the URL resource or continue a user activity, otherwise return true . The return value is ignored if the app is launched as a result of a remote notification.

What is NSUserActivity Swift?

An NSUserActivity object provides a lightweight way to capture the state of your app and put it to use later. Create this object to capture information about what a person was doing, such as viewing app content, editing a document, viewing a web page, or watching a video.

What does it mean to return false from an event handler?

When you return false; from an event handler it prevents the default action for that event and stops the event bubbling up through the DOM. It is effectively the same as calling both e.preventDefault and e.stopPropagation on the passed jQuery.Event object.

What is an example of a default action returning false?

Here is a simple example: That code would append the href attribute as text to the body every time a link was clicked but not actually go to that link. The return false; part of that code prevents the browser from performing the default action for that link. That exact thing could be written like this:

What is the difference between event preventDefault () and return false?

For example, in a submit event, it doesn't submit the form. return false also stops bubbling, so the parents of the element won't know the event occurred. return false is equivalent to event.preventDefault () + event.stopPropagation ()

What happens if you return false from a jQuery event?

What happen if you return false from a jQuery event handler? When you return false; from an event handler it prevents the default action for that event and stops the event bubbling up through the DOM. It is effectively the same as calling both e.preventDefault and e.stopPropagation on the passed jQuery.Event object.


1 Answers

Actually, for continueUserActivity the description of the return value is:

Returns true to indicate that your app handled the activity or false to let iOS know that your app did not handle the activity.

If you return YES from this function the OS will understand that no further processing of the NSUserActivity will be required - your app has done everything that needs to be done. If you return NO from this function, the OS will understand that an activity requiring OS processing may have occurred and may need to be handled.

You can get more background on all this in Apple's Handoff docs, here: https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/Handoff/HandoffFundamentals/HandoffFundamentals.html#//apple_ref/doc/uid/TP40014338

like image 55
dwestgate Avatar answered Oct 22 '22 20:10

dwestgate