pi1000 pi1000 - 1 year ago 246
Objective-C Question

Sample code on dynamic UIApplicationShortcutItems (Objective-C)

I'm looking after some sample code for a dynamic

using the Objective-C language.

Basically, I have three static
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
, so I'm looking after a simple way to add dynamic

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

Answer Source

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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download