Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick Actions events are never called #13634

Closed
Solido opened this issue Dec 16, 2017 · 25 comments · Fixed by flutter/plugins#3811
Closed

Quick Actions events are never called #13634

Solido opened this issue Dec 16, 2017 · 25 comments · Fixed by flutter/plugins#3811
Labels
customer: crowd Affects or could affect many people, though not necessarily a specific customer. p: quick_actions QuickActions plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels.

Comments

@Solido
Copy link
Contributor

Solido commented Dec 16, 2017

quickActions.initialize((String shortcutType) is never called.

Item are presented under IOS but a selection always return the default main widget
and debugger is never triggered under initialize(). Simple print never display the message.
V 0.0.2

Running flutter doctor...
[✓] Flutter (on Mac OS X 10.13.2 17C88, locale en-FR, channel master)
    • Flutter at /Users/user/Install/flutter
    • Framework revision e2192a90fc (4 days ago), 2017-12-15 19:10:18 -0800
    • Engine revision d945976b04
    • Tools Dart version 1.25.0-dev.11.0
    • Engine Dart version 2.0.0-edge.102a3c8e728a5e92a913cace4553995f8421f3e5

[✓] iOS toolchain - develop for iOS devices (Xcode 9.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.2, Build version 9C40b
    • ios-deploy 1.9.2
    • CocoaPods version 1.3.1
@Hixie Hixie added platform-ios iOS applications specifically framework flutter/packages/flutter repository. See also f: labels. engine flutter/engine repository. See also e: labels. labels May 22, 2018
@Hixie Hixie added this to the Goals milestone May 22, 2018
@Hixie
Copy link
Contributor

Hixie commented May 22, 2018

cc @cbracken

@ejabu
Copy link

ejabu commented May 24, 2018

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hehe/io.flutter.plugins.quickactions.QuickActionsPlugin$ShortcutHandlerActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.common.MethodChannel.invokeMethod(java.lang.String, java.lang.Object)' on a null object reference
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2706)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
	at android.app.ActivityThread.-wrap12(ActivityThread.java)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1514)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:163)
	at android.app.ActivityThread.main(ActivityThread.java:6221)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.common.MethodChannel.invokeMethod(java.lang.String, java.lang.Object)' on a null object reference
	at io.flutter.plugins.quickactions.QuickActionsPlugin$ShortcutHandlerActivity.onCreate(QuickActionsPlugin.java:117)
	at android.app.Activity.performCreate(Activity.java:6875)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
	... 9 more

I am running on Xiami 5A.

@DanielSmith1239
Copy link

I'm having this error too on my iPhone.

@DanielSmith1239
Copy link

DanielSmith1239 commented May 27, 2018

I found a temporary solution to the problem. Add the following code to your AppDelegate file:

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler {
    FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;
    
    FlutterMethodChannel* channel = [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/quick_actions" binaryMessenger:controller];
    [channel invokeMethod:@"launch" arguments:shortcutItem.type];
}

@artur-ios-dev
Copy link
Contributor

artur-ios-dev commented Aug 30, 2018

@DanielSmith1239 Thank you, it works! :) I hope it will be fixed though.

@goderbauer goderbauer added plugin and removed engine flutter/engine repository. See also e: labels. framework flutter/packages/flutter repository. See also f: labels. platform-ios iOS applications specifically labels Dec 28, 2018
@rodydavis
Copy link
Contributor

Thanks @DanielSmith1239 thats works for iOS! Do we need to add anything for Android?

@zoechi zoechi added the p: quick_actions QuickActions plugin label Jan 7, 2019
@workerbee22
Copy link

quick_actions code provided in repo for the package /example does not work at all on iOS 12.x.

@rodydavis
Copy link
Contributor

@workerbee22 if you add the code to the app delete it works perfectly

@workerbee22
Copy link

Added @DanielSmith1239 code to project into /ios/runner/appdelegate.m still nothing using the Pub version of the package 0.2.2. Did a flutter clean first ... nope nothing, regardless of if the app is running or not.

@workerbee22
Copy link

workerbee22 commented Jan 13, 2019

You guys are right !!! But traps for Flutter devs not accustomed to the iOS environment are:

  1. 3D Touch only supported on specific phones (see Apple doc for all devices). I was using a physical iPhone 6 and iPhone XR ... so an old and new device, NEITHER support 3D Touch !!! oops

iPhone 6s, iPhone 6s Plus, iPhone 7, iPhone 7 Plus, iPhone 8, iPhone 8 Plus, iPhone X, iPhone Xs, iPhone Xs Max
The iPhone XR, which was released in 2018, does not have 3D Touch.

  1. How do I 3D Touch in Simulator? Simulator for example using a iPhone Xs Max. To simulate a 'long press' or 3D touch, note you cannot use a mouse !!! In the Xcode Simulator, you need to have Hardware / Touch Pressure / Use Trackpad Force ENABLED !!! So you need a MacBook Pro with a Force enabled trackpad ... luckily mine is.

Then it works including the fix in AppDelegate.m from @DanielSmith1239 . Also seems to work if the app is running in the background, or from cold start of the app.

image

@xyzbilal
Copy link

for those who use swift as a IOS language. the code below is useful to run quick actions.

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    let controller = window.rootViewController as? FlutterViewController

    let channel = FlutterMethodChannel(name: "plugins.flutter.io/quick_actions", binaryMessenger: controller)
    channel.invokeMethod("launch", arguments: shortcutItem.type)
}

@Solido
Copy link
Contributor Author

Solido commented Feb 17, 2019

Remember to upvote this issue so the Flutter Team can give it a priority if it deserve it.

@rodydavis
Copy link
Contributor

For anyone curious this is what the AppDelagate.swift should look like with the latest swift syntax:

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    
@available(iOS 9.0, *)
override func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    let controller = window.rootViewController as? FlutterViewController
    
    let channel = FlutterMethodChannel(name: "plugins.flutter.io/quick_actions", binaryMessenger: controller!)
    channel.invokeMethod("launch", arguments: shortcutItem.type)
    }
}

@dustinsterk
Copy link

Thank you for this! Could not figure out why those actions were not being triggered. Worked perfect.

@britannio
Copy link

britannio commented Mar 7, 2020

The previous Swift solutions weren't compiling
The following code works for me.
I'm on the master branch.

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
  
// Required for the quick_actions package
@available(iOS 9.0, *)
override func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
    
    let channel = FlutterMethodChannel(name: "plugins.flutter.io/quick_actions", binaryMessenger: controller.binaryMessenger)
    channel.invokeMethod("launch", arguments: shortcutItem.type)
    }
}

@TahaTesser TahaTesser added the customer: crowd Affects or could affect many people, though not necessarily a specific customer. label Mar 16, 2020
@kf6gpe kf6gpe added the P2 Important issues not at the top of the work list label May 29, 2020
@Hixie Hixie removed this from the None. milestone Aug 17, 2020
vHanda added a commit to GitJournal/GitJournal that referenced this issue Oct 20, 2020
@filly82
Copy link

filly82 commented Oct 29, 2020

The previous Swift solutions weren't compiling
The following code works for me.
I'm on the master branch.

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
  
// Required for the quick_actions package
@available(iOS 9.0, *)
override func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
    
    let channel = FlutterMethodChannel(name: "plugins.flutter.io/quick_actions", binaryMessenger: controller.binaryMessenger)
    channel.invokeMethod("launch", arguments: shortcutItem.type)
    }
}

Works for me, thanks. But only if the App is already Running in the background. Unfortunately it does not work with a cold Start

@britannio
Copy link

britannio commented Oct 30, 2020

The previous Swift solutions weren't compiling
The following code works for me.
I'm on the master branch.

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
  
// Required for the quick_actions package
@available(iOS 9.0, *)
override func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
    
    let channel = FlutterMethodChannel(name: "plugins.flutter.io/quick_actions", binaryMessenger: controller.binaryMessenger)
    channel.invokeMethod("launch", arguments: shortcutItem.type)
    }
}

Works for me, thanks. But only if the App is already Running in the background. Unfortunately it does not work with a cold Start

I'm facing this issue but only on my most recent app. Android works flawlessly.

@Vanilo
Copy link

Vanilo commented Nov 23, 2020

Works for me, thanks. But only if the App is already Running in the background. Unfortunately it does not work with a cold Start

PerformActionFor::shortcutItem won't get called from cold start. Instead, the didFinishLaunchingWithOptions will get called from cold start. You need to check the launchOption in didFinishLaunhingWIthOptions for the shortcutItem, store to a variable and handle it in applicationDidBecomeActive.

Here are the codes:

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    
    var launchedShortcutItem: UIApplicationShortcutItem?

    override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        GeneratedPluginRegistrant.register(with: self)
        if let shortcutItem = launchOptions?[UIApplication.LaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
            launchedShortcutItem = shortcutItem
        }
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)

    }

    override func applicationDidBecomeActive(_ application: UIApplication) {    
        if(launchedShortcutItem != nil){
            handleShortcutItem(shortcutItem: launchedShortcutItem!.type)
            launchedShortcutItem = nil
        }
    }

    override func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
        handleShortcutItem(shortcutItem:shortcutItem.type)
    }

    private func handleShortcutItem(shortcutItem : String){
        let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
        let channel = FlutterMethodChannel(name: "plugins.flutter.io/quick_actions", binaryMessenger: controller.binaryMessenger)
        channel.invokeMethod("launch", arguments: shortcutItem)
    }

}

@britannio
Copy link

Works for me, thanks. But only if the App is already Running in the background. Unfortunately it does not work with a cold Start

PerformActionFor::shortcutItem won't get called from cold start. Instead, the didFinishLaunchingWithOptions will get called from cold start. You need to check the launchOption in didFinishLaunhingWIthOptions for the shortcutItem, store to a variable and handle it in applicationDidBecomeActive.

Here are the codes:

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    
    var launchedShortcutItem: UIApplicationShortcutItem?

    override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        GeneratedPluginRegistrant.register(with: self)
        if let shortcutItem = launchOptions?[UIApplication.LaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
            launchedShortcutItem = shortcutItem
        }
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)

    }

    override func applicationDidBecomeActive(_ application: UIApplication) {    
        if(launchedShortcutItem != nil){
            handleShortcutItem(shortcutItem: launchedShortcutItem!.type)
            launchedShortcutItem = nil
        }
    }

    override func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
        handleShortcutItem(shortcutItem:shortcutItem.type)
    }

    private func handleShortcutItem(shortcutItem : String){
        let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
        let channel = FlutterMethodChannel(name: "plugins.flutter.io/quick_actions", binaryMessenger: controller.binaryMessenger)
        channel.invokeMethod("launch", arguments: shortcutItem)
    }

}

@Vanilo This works like a charm! Are there any technical limitations that prevent this plugin from making this process easier? Ideally, we wouldn't need to touch AppDelegate.swift as users.

@Vanilo
Copy link

Vanilo commented Nov 23, 2020

@britannio I'm afraid this is the only way to do it as far as I know. There are only a few features that would require to make changes like this.

@filly82
Copy link

filly82 commented Nov 24, 2020

@Vanilo thanks man! worked for me as well

@britannio
Copy link

@Vanilo Does this look relevant? flutter/plugins#2887

@mvanbeusekom
Copy link

Wondering if this is still an issue. A fix is supplied since version 0.5.0 and since then I cannot reproduce the problem anymore.

The fix only listens to the application: performActionFor: method my tests seem to work fine for both a cold and a hot start of the App. I have also written a XCUITest to confirm the behaviour on both cold and hot start which also doesn't show any issue.

If you still experience the issue, would you please provide the following information:

  • The version of the plugin you are using;
  • The output of the flutter doctor -v command;
  • The code in your ios/Runner/AppDelegate.m file.

@mvanbeusekom mvanbeusekom added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 14, 2021
@Solido
Copy link
Contributor Author

Solido commented Apr 15, 2021

Hi @mvanbeusekom
Based on your response I close the issue
Thank you

@Solido Solido closed this as completed Apr 15, 2021
@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 15, 2021
@github-actions
Copy link

github-actions bot commented Aug 3, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2021
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
customer: crowd Affects or could affect many people, though not necessarily a specific customer. p: quick_actions QuickActions plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels.
Projects
None yet
Development

Successfully merging a pull request may close this issue.