gpt4 book ai didi

objective-c - 3DTouch 主屏幕快速操作

转载 作者:行者123 更新时间:2023-12-04 16:11:08 25 4
gpt4 key购买 nike

我想知道如何创建 View 快捷方式的链接?

如何将快捷方式 3DTOUCH 图标主屏幕连接到正确的应用程序 View 。例如:将 3DTouch 主屏幕快速操作设置连接到我的设置应用程序 View ?

screenshot

最佳答案

在这里,我发布了通过 iOS 以编程方式添加快捷方式的答案。

将此代码包含在 appdelegate.m 中

- (void)configDynamicShortcutItems {

// config image shortcut items
// if you want to use custom image in app bundles, use iconWithTemplateImageName method
UIApplicationShortcutIcon *shortcutAddIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];
// UIApplicationShortcutIcon *shortcutFavoriteIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeShare];

UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"facebookRXTA.png"];
UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"GoogleRXTA.png"];

UIApplicationShortcutItem *shortcutSearch = [[UIApplicationShortcutItem alloc]
initWithType:@"com.youapp.bundleid.Facebook"
localizedTitle:@"Facebook"
localizedSubtitle:nil
icon:icon1
userInfo:nil];

UIApplicationShortcutItem *shortcutFavorite = [[UIApplicationShortcutItem alloc]
initWithType:@"com.youapp.bundleid.Google"
localizedTitle:@"Google"
localizedSubtitle:nil
icon:icon2
userInfo:nil];

UIApplicationShortcutItem *shortcutAdd = [[UIApplicationShortcutItem alloc]
initWithType:@"com.youapp.bundleid.Create new user"
localizedTitle:@"Create new user"
localizedSubtitle:nil
icon:shortcutAddIcon
userInfo:nil];


// add all items to an array
NSArray *items = @[shortcutSearch, shortcutFavorite,shortcutAdd];

// add the array to our app
[UIApplication sharedApplication].shortcutItems = items;
}
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{

BOOL handledShortCutItem = [self handleShortCutItem:shortcutItem];

completionHandler(handledShortCutItem);
}
- (BOOL)handleShortCutItem : (UIApplicationShortcutItem *)shortcutItem{

BOOL handled = NO;

NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;

NSString *shortcutSearch = [NSString stringWithFormat:@"%@.Facebook", bundleId];
NSString *shortcutFavorite = [NSString stringWithFormat:@"%@.Google", bundleId];
NSString *shortcutAdd = [NSString stringWithFormat:@"%@.Create new user", bundleId];


if ([shortcutItem.type isEqualToString:shortcutSearch]) {
handled = YES;

//Do your navigation or your etc....

}

else if ([shortcutItem.type isEqualToString:shortcutFavorite]) {
handled = YES;

//Do your navigation or your etc....
}

return handled;
}

关于objective-c - 3DTouch 主屏幕快速操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41135390/

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