动态UIApplicationShortcutItems上的示例代码

fre*_*dpi 12 objective-c ios9

我正在寻找一些动态的Obj-C示例代码UIApplicationShortCutItem.

基本上,我有三个静态UIApplicationShortcutItems,我只想在某些条件下显示它们.我认为你不能改变静态的可见状态UIApplicationShortcutItem,所以我正在寻找一种简单的方法来添加动态UIApplicationShortcutItems.

che*_*pei 21

您可以使用以下代码为app动态添加shortcutitem:

UIApplicationShortcutIcon * photoIcon = [UIApplicationShortcutIcon iconWithTemplateImageName: @"selfie-100.png"]; // your customize icon
UIApplicationShortcutItem * photoItem = [[UIApplicationShortcutItem alloc]initWithType: @"selfie" localizedTitle: @"take selfie" localizedSubtitle: nil icon: photoIcon userInfo: nil];
UIApplicationShortcutItem * videoItem = [[UIApplicationShortcutItem alloc]initWithType: @"video" localizedTitle: @"take video" localizedSubtitle: nil icon: [UIApplicationShortcutIcon iconWithType: UIApplicationShortcutIconTypeCaptureVideo] userInfo: nil];

[UIApplication sharedApplication].shortcutItems = @[photoItem,videoItem];
Run Code Online (Sandbox Code Playgroud)