2011-07-14 44 views

回答

3

設置fireDate至晚上8時,設置repeatIntervalNSDayCalendarUnit和安排與[[UIApplication sharedApplication] scheduleLocalNotification: myNotification];

+0

即使手機設置爲靜音模式,是否可以強制UILocalNotification發出聲音? – Anthony

+0

即使應用程序沒有在後臺運行,它也能工作嗎? – Satyam

+0

是的,它會的。這是魔法。 – dasdom

2

dasdom答案警告是正確的。只是想增加它,如果您的設備處於靜音模式,鬧鐘不會發出聲音。這是Apple對UILocalNotification的限制。

+0

它應該是!當我希望手機保持沉默時,我不希望任何應用程序出現問題! – dasdom

0
UILocalNotification *localNotification =[[UILocalNotification alloc]init]; 

NSCalendar *calendar=[NSCalendar currentCalendar]; 
    [calendar setTimeZone:[NSTimeZone defaultTimeZone]]; 

    unsigned currentFlag=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit|NSWeekdayCalendarUnit; 

    NSDateComponents *comp=[calendar components:currentFlag fromDate:[NSDate date]]; 

    comp.hour=8; 
    comp.minute=0; 
    comp.second=0; 

    NSDate *date=[[calendar dateFromComponents:comp]dateByAddingTimeInterval:0]; 

    if (localNotification==nil) { 
     return; 
    } 

    localNotification.fireDate=date; 
    localNotification.timeZone=[NSTimeZone defaultTimeZone]; 
    localNotification.repeatCalendar=[NSCalendar currentCalendar]; 

    [email protected]"Good Morning dude..!"; 

    [email protected]"Snooze"; 

    localNotification.repeatInterval=NSDayCalendarUnit; 

    [email protected]"goodmorning.caf"; 

[[UIApplication sharedApplication]scheduleLocalNotification:localNotification]; 

我希望這將幫助你......!