3DTouch使用

- (void)createDynamicShortcutItems {

    // create several (dynamic) shortcut items
    UIApplicationShortcutItem *item1 = [[UIApplicationShortcutItem alloc]initWithType:@"Item 1" localizedTitle:@"Item 1"];
    UIApplicationShortcutItem *item2 = [[UIApplicationShortcutItem alloc]initWithType:@"Item 2" localizedTitle:@"Item 2"];
    UIApplicationShortcutItem *item3 = [[UIApplicationShortcutItem alloc]initWithType:@"Item 3" localizedTitle:@"Item 3"];

    // add all items to an array
    NSArray *items = @[item1, item2, item3];

    // add the array to our app
    [UIApplication sharedApplication].shortcutItems = items;
}

修改

- (void)modDynamicShortcutItems
{
    NSArray <UIApplicationShortcutItem *> *existingShortcutItems = [[UIApplication sharedApplication] shortcutItems];
    
    NSInteger anIndex = 1;
    UIApplicationShortcutItem *anExistingShortcutItem = [existingShortcutItems objectAtIndex: anIndex];
 
    NSMutableArray <UIApplicationShortcutItem *> *updatedShortcutItems = [existingShortcutItems mutableCopy];
    
    UIMutableApplicationShortcutItem *aMutableShortcutItem = [anExistingShortcutItem mutableCopy];
    [aMutableShortcutItem setLocalizedTitle: @"New Title"];
    [updatedShortcutItems replaceObjectAtIndex: anIndex withObject: aMutableShortcutItem];
    [[UIApplication sharedApplication] setShortcutItems: updatedShortcutItems];
}


静态info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<dict>
		<key>UIApplicationShortcutItemIconType</key>
		<string>UIApplicationShortcutIconTypeSearch</string>
		<key>UIApplicationShortcutItemSubtitle</key>
		<string>shortcutSubtitle1</string>
		<key>UIApplicationShortcutItemTitle</key>
		<string>shortcutTitle1</string>
		<key>UIApplicationShortcutItemType</key>
		<string>$(PRODUCT_BUNDLE_IDENTIFIER).First</string>
		<key>UIApplicationShortcutItemUserInfo</key>
		<dict>
			<key>firstShorcutKey1</key>
			<string>firstShortcutKeyValue1</string>
		</dict>
	</dict>
	<dict>
		<key>UIApplicationShortcutItemIconType</key>
		<string>UIApplicationShortcutIconTypeShare</string>
		<key>UIApplicationShortcutItemSubtitle</key>
		<string>shortcutSubtitle2</string>
		<key>UIApplicationShortcutItemTitle</key>
		<string>shortcutTitle2</string>
		<key>UIApplicationShortcutItemType</key>
		<string>$(PRODUCT_BUNDLE_IDENTIFIER).Second</string>
		<key>UIApplicationShortcutItemUserInfo</key>
		<dict>
			<key>secondShortcutKey1</key>
			<string>secondShortcutValue1</string>
		</dict>
	</dict>
</array>
</plist>

swift



官方参考 :

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationShortcutItem_class/index.html#//apple_ref/doc/uid/TP40016501-CH1-SW8

文档 概述https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/Adopting3DTouchOniPhone/3DTouchAPIs.html#//apple_ref/doc/uid/TP40016543-CH4-SW1

http://ourjs.com/detail/560baa8ee3312b046d27f53a


你可能感兴趣的:(3DTouch使用)