2015-04-30 3 views
0

Я хочу отображать локальное уведомление в своем приложении в определенный день, например, я хочу, чтобы уведомление отображалось на все 1 месяца.Локальное уведомление с конкретным днем ​​в iOS8

У меня есть этот код, как его настроить?

//LOcal Notification 

    NSDate *today = [NSDate new]; 
    NSCalendar *gregorian = 
    [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 

    NSDateComponents *offsetComponents = [NSDateComponents new]; 
    [offsetComponents setDay:???]; 
    [offsetComponents setHour:10]; 
    [offsetComponents setMinute:0]; 

    NSDate *thedate = [gregorian dateByAddingComponents:offsetComponents 
                toDate:today options:0]; 
    UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 
    localNotification.fireDate = thedate; 
    localNotification.alertBody = @"Hey, il serait temps de faire un point non ? \ue104"; 
    localNotification.timeZone = [NSTimeZone defaultTimeZone]; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
    //END 

Существует слишком обесцененная ошибка с ios8 в gregorian календаре, как я могу его решить?

+1

Амортизированное предупреждение не является ошибкой, вы все равно можете использовать его. Нажмите 'cmd + click' на' NSGregorianCalendar', который поможет вам использовать вместо устаревшего. – iphonic

+0

Xcode говорит: FOUNDATION_EXPORT NSString * const NSGregorianCalendar NS_CALENDAR_DEPRECATED (10_4, 10_10, 2_0, 8_0, «Вместо этого используйте NSCalendarIdentifierGregorian»); , нормально, но, как ? и где ? – ewan

+0

Оба вопроса были заданы перед: http://stackoverflow.com/questions/25626823/how-to-support-nscalendar-with-both-ios-7-and-8 HTTP://stackoverflow.com/questions/6966365/uilocalnotification-repeat-interval-for-custom-alarm-sun-mon-tue-wed-thu-f – Tapani

ответ

0
//assuming you want to fire the notifiaction on 1st of every month. 
NSInteger desiredWeekday = 1;// it specifies on which day of month 
    NSRange weekDateRange = [[NSCalendar currentCalendar] maximumRangeOfUnit:NSWeekdayCalendarUnit]; 
    NSInteger daysInWeek = weekDateRange.length - weekDateRange.location + 1; 

    NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:[NSDate date]]; 
    NSInteger currentWeekday = dateComponents.weekday; 
    NSInteger differenceDays = (desiredWeekday - currentWeekday + daysInWeek) % daysInWeek; 
    NSDateComponents *daysComponents = [[NSDateComponents alloc] init]; 
    daysComponents.day = differenceDays; 
    NSDate *resultDate = [[NSCalendar currentCalendar] dateByAddingComponents:daysComponents toDate:[NSDate date] options:0]; 


UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 
    localNotification.fireDate = resultDate; 
    localNotification.alertBody = @"Hey, il serait temps de faire un point non ? \ue104"; 
    localNotification.timeZone = [NSTimeZone defaultTimeZone]; 

    localNotification.repeatInterval = NSMonthCalendarUnit;// repeat notifiaction after a month 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
+0

Спасибо, как я могу его проверить? – ewan

+0

Я думаю, что у вас есть Google! Тогда учись. – Vizllx

Смежные вопросы