pi1000 pi1000 - 4 months ago 73
Objective-C Question

Sample code on dynamic UIApplicationShortcutItems (Objective-C)

I'm looking after some sample code for a dynamic

UIApplicationShortCutItem
using the Objective-C language.

Basically, I have three static
UIApplicationShortcutItems
and I only want to display them when a specific boolean in my app is true. I presume that you can't change the visible state of a static
UIApplicationShortcutItem
, so I'm looking after a simple way to add dynamic
UIApplicationShortcutItem
s.

Does anybody know a good tutorial (Objective-C) about this or has even some sample code to add dynamic
UIApplicationShortcutItem
s to my app?

Answer

You can use the following code to add shortcutitem for you app dynamic:

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];
Comments