Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
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
reformat obj-c
  • Loading branch information
olivierbrand committed Jul 21, 2020
commit 105c51b626e00a608905f6568b2fb2e76271b0cc
116 changes: 58 additions & 58 deletions packages/quick_actions/ios/Classes/FLTQuickActionsPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,93 +14,93 @@ @interface FLTQuickActionsPlugin ()
@implementation FLTQuickActionsPlugin

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
FlutterMethodChannel *channel =
[FlutterMethodChannel methodChannelWithName:CHANNEL_NAME
binaryMessenger:[registrar messenger]];
FLTQuickActionsPlugin *instance = [[FLTQuickActionsPlugin alloc] init];
instance.channel = channel;
[registrar addMethodCallDelegate:instance channel:channel];
[registrar addApplicationDelegate:instance];
FlutterMethodChannel *channel =
[FlutterMethodChannel methodChannelWithName:CHANNEL_NAME
binaryMessenger:[registrar messenger]];
FLTQuickActionsPlugin *instance = [[FLTQuickActionsPlugin alloc] init];
instance.channel = channel;
[registrar addMethodCallDelegate:instance channel:channel];
[registrar addApplicationDelegate:instance];
}

- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
if (@available(iOS 9.0, *)) {
if ([call.method isEqualToString:@"setShortcutItems"]) {
_setShortcutItems(call.arguments);
result(nil);
} else if ([call.method isEqualToString:@"clearShortcutItems"]) {
[UIApplication sharedApplication].shortcutItems = @[];
result(nil);
} else if ([call.method isEqualToString:@"getLaunchAction"]) {
result(self.shortcutType); // This is used when the app is killed and open the first time via
// quick actions
self.shortcutType = nil;
} else {
result(FlutterMethodNotImplemented);
}
if (@available(iOS 9.0, *)) {
if ([call.method isEqualToString:@"setShortcutItems"]) {
_setShortcutItems(call.arguments);
result(nil);
} else if ([call.method isEqualToString:@"clearShortcutItems"]) {
[UIApplication sharedApplication].shortcutItems = @[];
result(nil);
} else if ([call.method isEqualToString:@"getLaunchAction"]) {
result(self.shortcutType); // This is used when the app is killed and open the first time via
// quick actions
self.shortcutType = nil;
} else {
NSLog(@"Shortcuts are not supported prior to iOS 9.");
result(nil);
result(FlutterMethodNotImplemented);
}
} else {
NSLog(@"Shortcuts are not supported prior to iOS 9.");
result(nil);
}
}

- (void)dealloc {
[_channel setMethodCallHandler:nil];
_channel = nil;
[_channel setMethodCallHandler:nil];
_channel = nil;
}

- (BOOL)application:(UIApplication *)application
WillFinishLaunchingWithOptions:
(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions {
if (@available(iOS 9.0, *)) {
UIApplicationShortcutItem *shortcutItem =
launchOptions[UIApplicationLaunchOptionsShortcutItemKey];
if (shortcutItem != NULL) {
self.shortcutType = shortcutItem.type;
[self.channel invokeMethod:@"launch" arguments:shortcutItem.type];
return NO;
} else {
[self.channel invokeMethod:@"launch" arguments:nil];
self.shortcutType = nil;
}
if (@available(iOS 9.0, *)) {
UIApplicationShortcutItem *shortcutItem =
launchOptions[UIApplicationLaunchOptionsShortcutItemKey];
if (shortcutItem != NULL) {
self.shortcutType = shortcutItem.type;
[self.channel invokeMethod:@"launch" arguments:shortcutItem.type];
return NO;
} else {
[self.channel invokeMethod:@"launch" arguments:nil];
self.shortcutType = nil;
}
return YES;
}
return YES;
}

- (BOOL)application:(UIApplication *)application
performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem
completionHandler:(void (^)(BOOL succeeded))completionHandler
API_AVAILABLE(ios(9.0)) {
self.shortcutType = shortcutItem.type;
[self.channel invokeMethod:@"launch" arguments:shortcutItem.type];
return YES;
self.shortcutType = shortcutItem.type;
[self.channel invokeMethod:@"launch" arguments:shortcutItem.type];
return YES;
}

#pragma mark Private functions

NS_INLINE void _setShortcutItems(NSArray *items) API_AVAILABLE(ios(9.0)) {
NSMutableArray<UIApplicationShortcutItem *> *newShortcuts = [[NSMutableArray alloc] init];
for (id item in items) {
UIApplicationShortcutItem *shortcut = _deserializeShortcutItem(item);
[newShortcuts addObject:shortcut];
}
[UIApplication sharedApplication].shortcutItems = newShortcuts;
NSMutableArray<UIApplicationShortcutItem *> *newShortcuts = [[NSMutableArray alloc] init];

for (id item in items) {
UIApplicationShortcutItem *shortcut = _deserializeShortcutItem(item);
[newShortcuts addObject:shortcut];
}

[UIApplication sharedApplication].shortcutItems = newShortcuts;
}

NS_INLINE UIApplicationShortcutItem *_deserializeShortcutItem(NSDictionary *serialized)
API_AVAILABLE(ios(9.0)) {
UIApplicationShortcutIcon *icon =
[serialized[@"icon"] isKindOfClass:[NSNull class]]
? nil
: [UIApplicationShortcutIcon iconWithTemplateImageName:serialized[@"icon"]];
return [[UIApplicationShortcutItem alloc] initWithType:serialized[@"type"]
localizedTitle:serialized[@"localizedTitle"]
localizedSubtitle:nil
icon:icon
userInfo:nil];
UIApplicationShortcutIcon *icon =
[serialized[@"icon"] isKindOfClass:[NSNull class]]
? nil
: [UIApplicationShortcutIcon iconWithTemplateImageName:serialized[@"icon"]];

return [[UIApplicationShortcutItem alloc] initWithType:serialized[@"type"]
localizedTitle:serialized[@"localizedTitle"]
localizedSubtitle:nil
icon:icon
userInfo:nil];
}

@end