如何动态设置强制触摸标题

时间:2015-10-18 22:29:31

标签: ios dynamic touch title

我为我的应用添加了力量触摸,这很有效:)。但是我希望这些标题能够改变为首先出现的任何约会。将日期设置为副标题。

我看到Dropbox可以做到,所以有人能告诉我它是如何完成的吗?

enter image description here enter image description here

将其添加到您的info.plist中 enter image description here

UIApplicationShortcutItems
-- Item 0
    -- UIApplicationShortcutItemIconType = UIApplicationShortcutIconTypePlay
    -- UIApplicationShortcutItemTitle    = Present 
    -- UIApplicationShortcutItemUserInfo
        -- key1                           = 1
-- Item 1
°°°

并在您的委托文件中使用以下代码: 其中xxxxxx是您的PRODUCT_BUNDLE_IDENTIFIER

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler 
{
    int updateAttendance = 0;

    if ([shortcutItem.type isEqualToString:@"xxxxxx.setPresent"])
    {
        updateAttendance = 1;
    }
    if ([shortcutItem.type isEqualToString:@"xxxxxx.setAbsent"])
    {
        updateAttendance = 3;
    }
    if ([shortcutItem.type isEqualToString:@"xxxxxx.clearAllNotifications"])
    {
        [[beDbAccess sharedInstance] clearAllNotifications];
    }
    if (updateAttendance > 0)
    {
        [[beDbAccess sharedInstance] updateAttendanceNextPlan:updateAttendance];
    }
}

1 个答案:

答案 0 :(得分:0)

您可以按照here的说明进行操作,方法是在应用程序的didFinishLaunchingWithOptions方法内以编程方式添加UIApplicationShortcutIcon:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    let icon = UIApplicationShortcutIcon(type: .add)
    let item = UIApplicationShortcutItem(type: "com.yoursite.yourapp.adduser", localizedTitle: "Add User", localizedSubtitle: "Meet someone new", icon: icon, userInfo: nil)
    UIApplication.shared.shortcutItems = [item]

    if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
        if shortcutItem.type == "com.yoursite.yourapp.adduser" {
            // shortcut was triggered!
        }
    }

    return true
}