Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added comments to explain code
  • Loading branch information
mvanbeusekom committed Apr 18, 2021
commit 8b38c46d7a64870265a222598c5a38fdfb2eec5c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ - (BOOL)application:(UIApplication *)application
UIApplicationShortcutItem *shortcutItem =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we directly call handleShortcut here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to wait here for the application to become fully active before the method channel are fully initialised. When we directly call the handleShortcut in the didFinishLaunchingWithOptions method the channels on the Dart side are not initialised yet and the invokeMethod:@"launch" isn't processed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah makes sense. Let's add a comment here for future reference.

Why do we return No below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Apple's documentation you should return NO if you already handled the shortcut action which will make sure the application:performActionFor: method and not handle the same action again.

The explanation can be found in the last alinea of the "Discussion" section of this article: https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623032-application

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Let's also add comment here too. Then I think we are good to go!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cyanglaz, I have added comments as explanation.

launchOptions[UIApplicationLaunchOptionsShortcutItemKey];
if (shortcutItem) {
// Keep hold of the shortcut type and handle it in the
// `applicationDidBecomeActure:` method once the Dart MethodChannel
// is initialized.
self.shortcutType = shortcutItem.type;

// Return NO to indicate we handled the quick action to ensure
// the `application:performActionFor:` method is not called (as
// per Apple's documentation:
// https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622935-application?language=objc).
return NO;
}
}
Expand Down