---restore content starts---
The first is the installation of the plugin Sbshortcutmenusimulator
1, git clone https://github.com/DeskConnect/SBShortcutMenuSimulator.git2, CD SBShortcutMenuSimulator3, make
4, Xcrun simctl spawn booted launchctl debug System/com.apple.springboard--environment dyld_insert_libraries=$PWD/ Sbshortcutmenusimulator.dylib
5, Xcrun simctl Spawn booted Launchctl stop Com.apple.SpringBoard
When you are done configuring in Xcode, you can enter the following sentence on the command line to test it.
6、echo
‘com.apple.mobilecal‘
|
nc
127.0.0.1 8000
‘com.apple.mobilecal‘是项目的bundle ID
IOS9 provides us with two kinds of screen labels, static labels and dynamic tags, respectively.
1. Static label
A static label is a label that we configure in the configuration plist file of the project, which is available after the user installs the program, and the sort is preceded by a dynamic label.
Let's look at the configuration of the static tag first:
First of all, add the following key value in the Info.plist file (when I was testing, the system did not prompt, can only hand up):
An array of Uiapplicationshortcutitems is added first, and the elements added in this array are the corresponding static tags, and in each tag we need to add some key values for the setting:
Required (The following two key values must be set):
Uiapplicationshortcutitemtype This key value to set a shortcut channel type string
Uiapplicationshortcutitemtitle The title of this key value setting label
Optional (these key values are not required):
Uiapplicationshortcutitemsubtitle Setting the subtitle of a label
Uiapplicationshortcutitemicontype setting label icon type
Uiapplicationshortcutitemiconfile icon file for the Settings tab
Uiapplicationshortcutitemuserinfo setting information dictionary (for value transfer)
Run the following effect
2. Dynamic label
Dynamic tagging is a class that we add to our program by code, with three main categories:
Uiapplicationshortcutitem Creating a 3DTouch tag class
Uimutableapplicationshortcutitem Creating a variable 3DTouch Label class
Uiapplicationshortcuticon create a class for a picture icon in a label
Because these classes are newly added classes in IOS9, their APIs are not very complex, so let's briefly explain the methods and properties:
- (instancetype)initWithType:(NSString *)type localizedTitle:(NSString *)localizedTitle localizedSubtitle:(nullable NSString *)localizedSubtitle icon:(nullable UIApplicationShortcutIcon *)icon userInfo:(nullable NSDictionary *)userInfo NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithType:(NSString *)type localizedTitle:(NSString *)localizedTitle;
//下面这是一些只读的属性,获取相应的属性值
@property (nonatomic, copy, readonly) NSString *type;
@property (nonatomic, copy, readonly) NSString *localizedTitle;
@property (nullable, nonatomic, copy, readonly) NSString *localizedSubtitle;
@property (nullable, nonatomic, copy, readonly) UIApplicationShortcutIcon *icon;
@property (nullable, nonatomic, copy, readonly) NSDictionary<NSString *, id <NSSecureCoding>> *userInfo;
//这个类继承于 UIApplicationShortcutItem,创建的标签可变
@interface UIMutableApplicationShortcutItem : UIApplicationShortcutItem
@property (nonatomic, copy) NSString *type;
@property (nonatomic, copy) NSString *localizedTitle;
@property (nullable, nonatomic, copy) NSString *localizedSubtitle;
@property (nullable, nonatomic, copy) UIApplicationShortcutIcon *icon;
@property (nullable, nonatomic, copy) NSDictionary<NSString *, id <NSSecureCoding>> *userInfo;
@end
//这个类创建标签中的icon
@interface UIApplicationShortcutIcon : NSObject <NSCopying>
//创建系统风格的icon
+ (instancetype)iconWithType:(UIApplicationShortcutIconType)type;
//创建自定义的图片icon
+ (instancetype)iconWithTemplateImageName:(NSString *)templateImageName;
@end
Once you have created the tag, add it as a hortcutitems array of application, as shown in the following example:
var application = Uiapplication.sharedapplication ()
Override Func Viewdidload () {
Super.viewdidload ()
Let first = Uimutableapplicationshortcutitem (type: "Mudy1", Localizedtitle: "Mudy2", Localizedsubtitle: "Mudy3", Icon: Nil, Userinfo:nil)
Application.shortcutitems = [First]
}
The effect is as follows:
Here, the enumeration of system style icons is listed below:
typedef
NS_ENUM(NSInteger, UIApplicationShortcutIconType) {
UIApplicationShortcutIconTypeCompose,
//编辑的图标
UIApplicationShortcutIconTypePlay,
//播放图标
UIApplicationShortcutIconTypePause,
//暂停图标
UIApplicationShortcutIconTypeAdd,
//添加图标
UIApplicationShortcutIconTypeLocation,
//定位图标
UIApplicationShortcutIconTypeSearch,
//搜索图标
UIApplicationShortcutIconTypeShare
//分享图标
} NS_ENUM_AVAILABLE_IOS(9_0);
3. Response tag Behavior
Similar push, when we click on the tag to enter the application, we can also do some actions, we can see, in the Applocation added a method:
-(void) Application: (UIApplication *) application Performactionforshortcutitem: (uiapplicationshortcutitem*) Shortcutitem Completionhandler: (void (^) (BOOL succeeded)) Completionhandler Ns_available_ios (9_0);
When we enter the app through a tag, we call such a callback in Appdelegate, and we can get the Shortcutitem information for the relevant logical operation.
Here's one thing to note: Our entry function in the app:
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions;
Also need to make a judgment, in Launchoptions has uiapplicationlaunchoptionsshortcutitemkey such a key, through it, we can distinguish whether the app is entered from the tag, if it is the end logic processing, Returns no to prevent the processing logic from being repeatedly recalled.
Some notes:
1, the shortcut tag can create up to four, including static and dynamic.
2, the title of each label and icon at most two lines, the more will be used ... Omitted
---restore content ends---
Add 3DTouch in Xcode7