2012-11-01 17 views
10

पर क्लिक करते समय ऐप को कैसे खोलें मैं सूचनाओं को प्रदर्शित करने के लिए NSUserNotification का उपयोग कर रहा हूं। यह ठीक काम कर रहा है। समस्या यह है कि जब आप अधिसूचना पर क्लिक करते हैं:NSUserNotification -

  1. ऐप्स नोटिफिकेशन अधिसूचना केंद्र से नहीं हटाए जाते हैं।
  2. ऐप (जब न्यूनतम) खुला नहीं होता है।

एनएसयूसर नॉटिफिकेशन से परिचित कोई भी जो कुछ पॉइंटर्स पेश कर सकता है?

notice.m

#import "Notice.h" 

@implementation Notice 

- (void) notify:(NSDictionary *)message { 

    NSLog(@"Notification - Show it"); 

    NSUserNotification *notification = [[NSUserNotification alloc] init]; 
    [notification setTitle:[message valueForKey:@"title"]]; 
    [notification setInformativeText:[message valueForKey:@"content"]]; 
    [notification setDeliveryDate:[NSDate dateWithTimeInterval:0 sinceDate:[NSDate date]]]; 
    [notification setSoundName:NSUserNotificationDefaultSoundName]; 
    NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter]; 
    [center scheduleNotification:notification]; 
} 

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification 
{ 

    NSLog(@"Notification - Clicked"); 

    notification=nil; 
    [center removeDeliveredNotification: notification]; 
} 







#pragma mark WebScripting Protocol 

+ (BOOL) isSelectorExcludedFromWebScript:(SEL)selector 
{ 
    if (selector == @selector(notify:)) 
     return NO; 

    return YES; 
} 

+ (NSString*) webScriptNameForSelector:(SEL)selector 
{ 
    id result = nil; 

    if (selector == @selector(notify:)) { 
     result = @"notify"; 
    } 

    return result; 
} 

// right now exclude all properties (eg keys) 
+ (BOOL) isKeyExcludedFromWebScript:(const char*)name 
{ 
    return YES; 
} 

@end 

धन्यवाद

+0

[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate: self]; –

उत्तर

11

बस NSUserNotificationCenterDelegate को लागू करने और इस विधि को परिभाषित:

- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification 

उदाहरण:

यह है कि मैं क्या में किया था है एक "नोटिफी आर "आवेदन।

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification 
{ 
    NSRunAlertPanel([notification title], [notification informativeText], @"Ok", nil, nil); 
} 

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didDeliverNotification:(NSUserNotification *)notification 
{ 
    notifications=nil; 
    [tableView reloadData]; 
    [center removeDeliveredNotification: notification]; 
} 

जब अधिसूचना सक्रिय होता है (उपयोगकर्ता द्वारा क्लिक करें) मैं तो बस (मैं एक HUD खिड़की इस्तेमाल कर सकते हैं) एक पैनल के साथ उपयोगकर्ता को सूचित इस मामले .इसके मैं तुरंत वितरित सूचना को निकालने, लेकिन यह नहीं है क्या आमतौर पर होता है। अधिसूचना कुछ समय तक रह सकती है और 1/2 घंटों के बाद हटा दी जा सकती है (यह उस एप्लिकेशन पर निर्भर करता है जिसे आप विकसित कर रहे हैं)।

+5

वास्तव में खुद को प्रतिनिधि के रूप में सेट करना न भूलें। विशेष रूप से किसी को भी घोषित नहीं करना कि आप एक प्रतिनिधि बन सकते हैं यदि आप वास्तव में कभी भी प्रतिनिधि बनने के लिए कुछ भी नहीं प्राप्त करते हैं। –

+0

क्या आप उपरोक्त को अपडेट करना चाहते हैं तो मैं सीख सकता हूं? मैं नया हूं और रैंप करने की कोशिश कर रहा हूं। मैं इसकी प्रशंसा करता हूँ। – AnApprentice

+0

इसके अलावा, क्या यह अधिसूचनाओं को हटाने या कम से कम छिपे हुए दृश्य से ऐप खोलने के लिए है? मुझे लगता है कि मैंने दो प्रश्न पूछे हैं :) – AnApprentice