flutter中使用 quick_actions iOS不起作用解决方案

1.swift中AppDelegate加入

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool {
    print("App started")
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    
    //quick_actions item click not work, should copy this method to AppDelegate.swift�
    @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! as! FlutterBinaryMessenger)
    channel.invokeMethod("launch", arguments: shortcutItem.type)
    }
}
 
  1. oc中在AppDelegate.m中加入
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler{
    
    //static NSString *const CHANNEL_NAME = @"plugins.flutter.io/quick_actions";
    
    FlutterViewController *controller = (FlutterViewController *)self.window.rootViewController;
    FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:CHANNEL_NAME binaryMessenger:controller.binaryMessenger];
    [channel invokeMethod:@"launch" arguments:shortcutItem.type];
    
}

你可能感兴趣的:(flutter中使用 quick_actions iOS不起作用解决方案)