gpt4 book ai didi

ios - Obj-C 中的 3D Touch Home 快捷方式

转载 作者:IT王子 更新时间:2023-10-29 05:08:30 24 4
gpt4 key购买 nike

我所有的应用程序目前都是用 Obj-C 编写的。链接https://developer.apple.com/library/content/samplecode/ApplicationShortcuts/Introduction/Intro.html#//apple_ref/doc/uid/TP40016545对于使用 3D Touch 实现主屏幕快捷方式的示例代码完全在 Swift 中编译。任何人都看过 Obj-C 的文档,所以我不必通过我的 AppDelegate 来翻译它吗?

更新:

在Info.plist中添加所有快捷方式后,我在AppDelegate.m中添加:

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
UINavigationController *nav = (UINavigationController *) self.tabBarController.selectedViewController;

NSLog(@"%@", shortcutItem.type);
if ([shortcutItem.type isEqualToString:@"com.316apps.iPrayed.addPrayerRequest"]) {
Requests *gonow = [[Requests alloc] init];

[nav pushViewController:gonow animated:YES];

}
if ([shortcutItem.type isEqualToString:@"com.316apps.iPrayed.addPrayer"]) {

PrayerStats *controller = [[PrayerStats alloc] init];
[nav pushViewController:controller animated:YES];

}

if ([shortcutItem.type isEqualToString:@"com.316apps.iPrayed.addFast"]) {

FastStats *controller1 = [[FastStats alloc] init];
[nav pushViewController:controller1 animated:YES];

}

if ([shortcutItem.type isEqualToString:@"com.316apps.iPrayed.addStudy"]) {

StudyStats *controller2 = [[StudyStats alloc] init];
[nav pushViewController:controller2 animated:YES];

}
}

这允许它工作,无需放入任何其他方法,或向 didFinishLaunchingWithOptions 添加任何内容。

最佳答案

用户可以在两种状态下通过快速操作打开应用。

长话短说无论快速操作完成时应用程序的状态如何,您总是在做同样的事情,这就是为什么您只需要覆盖 application:performActionForShortcutItem:completionHandler: 所以如果您想做不同的事情事情,那么你会想在两个地方处理它们,如果不是那么只覆盖就足够了。

  • 一个是如果应用程序被终止或没有在后台运行,我们会在启动时获取快捷方式信息。

  • 另一种情况是,如果应用程序在后台运行,我们会在其中获取有关新应用程序委托(delegate)方法的快捷方式信息。

要在后台处理这些快速操作快捷方式,您需要在 App Delegate 上覆盖此方法:

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler

并且不在您的后台运行(终止)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions

您应该检查应用程序是否通过快速操作启动:

UIApplicationShortcutItem *shortcutItem = [launchOptions objectForKey:UIApplicationLaunchOptionsShortcutItemKey];

(Link to related Apple Documentation)引用自苹果官方文档

It’s your responsibility to ensure the system calls this method conditionally, depending on whether or not one of your app launch methods (application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions:) has already handled a quick action invocation. The system calls a launch method (before calling this method) when a user selects a quick action for your app and your app launches instead of activating.

The requested quick action might employ code paths different than those used otherwise when your app launches. For example, say your app normally launches to display view A, but your app was launched in response to a quick action that needs view B. To handle such cases, check, on launch, whether your app is being launched via a quick action. Perform this check in your application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: method by checking for the UIApplicationLaunchOptionsShortcutItemKey launch option key. The UIApplicationShortcutItem object is available as the value of the launch option key.

If you find that your app was indeed launched using a quick action, perform the requested quick action within the launch method and return a value of NO from that method. When you return a value of NO, the system does not call the application:performActionForShortcutItem:completionHandler: method.

关于ios - Obj-C 中的 3D Touch Home 快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32634024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com