Skip to content

Commit

Permalink
[new] iOS主屏幕快捷操作——课程表
Browse files Browse the repository at this point in the history
  • Loading branch information
zshengyan committed May 7, 2024
1 parent 7b14630 commit b3aaa1e
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 3 deletions.
21 changes: 21 additions & 0 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class AppDelegate: FlutterAppDelegate, GeTuiSdkDelegate {
GeTuiSdk.registerRemoteNotification([.alert, .badge, .sound])

GeneratedPluginRegistrant.register(with: self)

if let shortcutItem = launchOptions?[.shortcutItem] as? UIApplicationShortcutItem {
handleShortcutItem(shortcutItem, controller: controller)
}

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
Expand All @@ -42,4 +46,21 @@ class AppDelegate: FlutterAppDelegate, GeTuiSdkDelegate {
// 每次退出到桌面的时候刷新下
Channel.reloadWidgetData()
}

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

private func handleShortcutItem(_ shortcutItem: UIApplicationShortcutItem, controller: FlutterViewController) {
let channelName = "com.twt.service/shortcutItem"
let channel = FlutterMethodChannel(name: channelName, binaryMessenger: controller.binaryMessenger)
// 向Flutter发送快捷操作标识
channel.invokeMethod("onShortcutAction", arguments: shortcutItem.type)
}
}
6 changes: 6 additions & 0 deletions ios/Runner/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
23 changes: 23 additions & 0 deletions ios/Runner/Assets.xcassets/ShortcutQR.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,24 @@
<string>Automatic</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemType</key>
<string>com.twt.service.qr</string>
<key>UIApplicationShortcutItemTitle</key>
<string>入校码</string>
<key>UIApplicationShortcutItemIconFile</key>
<string>ShortcutQR</string>
</dict>
<dict>
<key>UIApplicationShortcutItemType</key>
<string>com.twt.service.courses</string>
<key>UIApplicationShortcutItemTitle</key>
<string>课程表</string>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypeDate</string>
</dict>
</array>
</dict>
</plist>
21 changes: 20 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class WePeiYangAppState extends State<WePeiYangApp>
@override
void initState() {
super.initState();

_listenForShortcutActions();
WidgetsBinding.instance.addObserver(this);
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
var baseContext =
Expand All @@ -219,6 +219,24 @@ class WePeiYangAppState extends State<WePeiYangApp>
_onBrightnessChanged;
}

Future<void> _listenForShortcutActions() async {
const methodChannel = MethodChannel('com.twt.service/shortcutItem');
// Dart端的方法监听
methodChannel.setMethodCallHandler((MethodCall call) async {
switch (call.method) {
case 'onShortcutAction':
String actionType = call.arguments;
if (actionType == "com.twt.service.courses") {
WePeiYangApp.navigatorState.currentState?.pushNamed(ScheduleRouter.course);
}
break;
default:
print('No action for ${call.method}');
}
});
}


void _onBrightnessChanged() async =>
await Future.delayed(Duration(milliseconds: 400)).then(
(_) => WpyTheme.updateAutoDarkTheme(context),
Expand All @@ -227,6 +245,7 @@ class WePeiYangAppState extends State<WePeiYangApp>
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
_listenForShortcutActions();
checkEventList();
}
}
Expand Down
2 changes: 0 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import share_plus
import shared_preferences_foundation
import sqflite
import url_launcher_macos
import video_player_avfoundation
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
Expand All @@ -31,6 +30,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
FVPVideoPlayerPlugin.register(with: registry.registrar(forPlugin: "FVPVideoPlayerPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}

0 comments on commit b3aaa1e

Please sign in to comment.