मैंने गिटहब पर एक साधारण उद्देश्य-सी उदाहरण पोस्ट किया है जो होम स्क्रीन पर शॉर्टकट जोड़/हटाता है।
आप इसे यहाँ देख सकते हैं:
- (BOOL)handleShortCutItem:(UIApplicationShortcutItem *)shortcutItem {
BOOL handled = NO;
if (shortcutItem == nil) {
return handled;
}
handled = YES;
UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"Handle Shortcut" message:shortcutItem.type delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[av show];
return handled;
}
यह: https://github.com/cjimenezpacho/3Dtouch-home-screen-quick-actions
मुझे लगता है कि शॉर्टकट आइटम (एक और stackoverflow जवाब है कि मैं नहीं मिला सकते हैं :(के आधार पर) संभालती अनुप्रयोग प्रतिनिधि पर एक विधि है आवेदन के द्वारा कहा जाता है: didFinishLaunchingWithOptions और आवेदन:। performActionForShortcutItem एप्लिकेशन या लॉन्च नहीं किया गया है या नहीं
और जोड़ने के लिए/मांग पर शॉर्टकट निकालने:
- (void) addActionToShortCutItems{
NSArray <UIApplicationShortcutItem *> *existingShortcutItems = [[UIApplication sharedApplication] shortcutItems];
if([existingShortcutItems count]){
NSMutableArray <UIApplicationShortcutItem *> *updatedShortcutItems = [existingShortcutItems mutableCopy];
NSInteger numberOfActions = [existingShortcutItems count];
[updatedShortcutItems addObject:[self createItemNumber:numberOfActions]];
[[UIApplication sharedApplication] setShortcutItems: updatedShortcutItems];
}else{
[UIApplication sharedApplication].shortcutItems = @[[self createItemNumber:0]];
}
}
- (UIApplicationShortcutItem*)createItemNumber:(NSInteger)number{
UIApplicationShortcutItem *newItem = [[UIApplicationShortcutItem alloc]initWithType:[NSString stringWithFormat:@"type%ld",number]
localizedTitle:[NSString stringWithFormat: NSLocalizedString(@"Action %ld", nil),number]
localizedSubtitle:nil
icon:nil
userInfo:nil];
return newItem;
}
- (void) removeActionToShortCutItems{
NSArray <UIApplicationShortcutItem *> *existingShortcutItems = [[UIApplication sharedApplication] shortcutItems];
NSMutableArray <UIApplicationShortcutItem *> *updatedShortcutItems = [existingShortcutItems mutableCopy];
[updatedShortcutItems removeObjectAtIndex:[updatedShortcutItems count]-1];
[[UIApplication sharedApplication] setShortcutItems: updatedShortcutItems];
}
उम्मीद है कि यह मदद करता है और प्रतिक्रिया का स्वागत है!
स्रोत
2015-12-16 10:17:08
उद्देश्य-सी में शॉर्टकट से कोई ऐप लॉन्च होने पर आप कैसे पता लगाते हैं? – user1752054
आप 'एप्लिकेशन में जांच सकते हैं: didFinishLaunchingWithOptions' या' application: willFinishLaunchingWithOptions: 'क्या ऐप शॉर्टकट से लॉन्च किया जा रहा है। अगर ऐप शॉर्टकट से लॉन्च किया गया है, तो लॉन्चऑप्शन डिक्शनरी में' यूआईएप्लिकेशंस लॉन्चऑप्शनशॉर्टकट इटैमकी 'शामिल होना चाहिए। और आप मेरे शॉर्टकूट डेमो रिपोजिटरी https को क्लोन कर सकते हैं : //github.com/cp0000/shortcutDemo, और अधिक जानकारी प्राप्त करें। – chengpei