美文网首页
flutter中使用 quick_actions iOS不起作用

flutter中使用 quick_actions iOS不起作用

作者: 喜剧收尾_XWX | 来源:发表于2021-02-18 16:14 被阅读0次

    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不起作用

          本文链接:https://www.haomeiwen.com/subject/pjcnxltx.html