2011-08-01 19 views
6

को सूचित करता है, इसलिए मैं मूल रूप से एक ऐप सेट करने की कोशिश कर रहा हूं जो स्थानीय नोटिफिकेशन को लगातार देता है।मैं UILocalNotification कैसे बना सकता हूं जो हर दो मिनट

अब तक मेरे पास है:

- (void)scheduleNotification { 

    [reminderText resignFirstResponder]; 
    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 

    Class cls = NSClassFromString(@"UILocalNotification"); 
    if (cls != nil) { 

     UILocalNotification *notif = [[cls alloc] init]; 
     notif.fireDate = [datePicker date]; 
     notif.timeZone = [NSTimeZone defaultTimeZone]; 

     notif.alertBody = @"Your building is ready!"; 
     notif.alertAction = @"View"; 
     notif.soundName = UILocalNotificationDefaultSoundName; 
     notif.applicationIconBadgeNumber = 1; 

     NSInteger index = [scheduleControl selectedSegmentIndex]; 
     switch (index) { 
      case 1: 
       notif.repeatInterval = NSMinuteCalendarUnit; 
       break; 
      case 2: 
       notif.repeatInterval = NSMinuteCalendarUnit*2; 
       break; 
      default: 
       notif.repeatInterval = 0; 
       break; 
     } 

     NSDictionary *userDict = [NSDictionary dictionaryWithObject:reminderText.text 
               forKey:kRemindMeNotificationDataKey]; 
     notif.userInfo = userDict; 

     [[UIApplication sharedApplication] scheduleLocalNotification:notif]; 
     [notif release]; 
    } 
} 

मैं तो मैं एक अधिसूचना हर 2 मिनट प्राप्त कर सकते हैं और हर 1 मिनट (जब मैं मामला 2 सेट) इसे बनाने के लिए कोशिश कर रहा हूँ (जब मैं मामले 1 सेट) सूचित किया जाना। एकमात्र समस्या यह है कि * 2 2 हर 2 मिनट में अधिसूचित होने के लिए काम नहीं कर रहा है। मैं इसे बनाने के बारे में कैसे जाउंगा ताकि यह हर 2 मिनट को सूचित करे?

उत्तर

2

आप केवल एनएससीलेंडरयूनीट में परिभाषित कैलेंडर इकाइयों का उपयोग कर सकते हैं जब आप दोहराना नॉटिफिकेशन की दोहराना अंतराल संपत्ति सेट कर रहे हैं। आप कस्टम इकाइयों का उपयोग नहीं कर सकते हैं या इकाइयों में हेरफेर नहीं कर सकते हैं, इसलिए आप अधिसूचना की दोहराव अंतराल संपत्ति का उपयोग करके जो भी करना चाहते हैं वह करने में सक्षम नहीं होंगे।

प्रत्येक 2 मिनट में अधिसूचनाओं को शेड्यूल करने के लिए, आप संभवतः अलग-अलग समय पर कई नोटिफिकेशन शेड्यूल करना चाहते हैं (2 मिनट अलग)। आप एक UILocalNotification बना सकते हैं, और फिर साथ यह अनुसूची:

[[UIApplication sharedApplication] scheduleLocalNotification: localNotification]; 

तो fireDate संपत्ति (अपने दोहराने अंतराल जोड़कर) को संशोधित, और फिर इसे फिर से अनुसूची एक ही कोड के साथ। आप इसे एक लूप में दोहरा सकते हैं हालांकि आपको अधिसूचना दोहराने की आवश्यकता होती है।

संबंधित मुद्दे