2017-01-02 1 views
0

私は特定の日のリマインダを設定する必要があるアプリケーションを開発しています。ローカル通知を使用して、現在の選択された曜日の日付を検索しています。なぜ私はローカル通知を受け取っていません。目的のCで1週間のリマインダを設定しているとき

これは私のコードされています。今、私は通知を受けていないよ

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { 
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; 
} 
// Handle launching from a notification 
UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; 
if (locationNotification) { 
    // Set icon badge number to zero 
    application.applicationIconBadgeNumber = 0; 
} 

return YES; 
} 
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
{ 
// Set icon badge number to zero 
    application.applicationIconBadgeNumber = 0; 
} 

appDelegateviewController.m

NSArray* components12 = [self.LblTime.text componentsSeparatedByString:@":"]; 
    NSString *Hours = [components12 objectAtIndex:0]; 
    NSString *Minutes =[components12 objectAtIndex:1]; 

    NSDate *currentDate = [NSDate date]; 
    NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
    [gregorianCalendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]]; 

    NSDateComponents *components = [gregorianCalendar components:(NSYearCalendarUnit| NSMonthCalendarUnit 
                    | NSDayCalendarUnit| NSWeekdayCalendarUnit|NSWeekCalendarUnit) fromDate:currentDate]; 

    NSLog(@"Current week day number %ld",(long)[components weekday]); 
    NSLog(@"Current week number %ld",(long)[components week]); 
    NSLog(@"Current month's day %ld",(long)[components day]); 
    NSLog(@"Current month %ld",(long)[components month]); 
    NSLog(@"Current year %ld",(long)[components year]); 

    NSDateComponents *dt=[[NSDateComponents alloc]init]; 
    //Passing the Time (hours and minutes) and Selected day with date 
    [dt setHour: [Hours integerValue]]; 
    [dt setMinute:[Minutes integerValue]]; 
    [dt setSecond:0]; 
    [dt setWeek:[components week]]; 
    [dt setWeekday:selecteddayValue];/// set the week Selected ay from picker 
    [dt setMonth:[components month]]; 
    [dt setYear:[components year]]; 
    NSDate *Date=[gregorianCalendar dateFromComponents:dt];// get the date of selected day of week 
    NSLog(@"Sunday date :%@",Date); 

    //Adding the reminder through Local notifiction 
    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 
    UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
    localNotification.fireDate =Date; 
    localNotification.alertBody = @"Ready For Next Workout!"; 
    localNotification.soundName = UILocalNotificationDefaultSoundName; 
    // localNotification.applicationIconBadgeNumber = 1; // increment 
    NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Object 1", @"Key 1", @"Object 2", @"Key 2", nil]; 
    localNotification.userInfo = infoDict; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
    [self showAlert:@"Reminder set Successfully"]; 

。だれでもthis.thatのために助けてください非常にapperitiateだろう。

+1

まず、iOS10ではUILocalNotificationは推奨されていません。代わりにUNUserNotificationCenterの使用を開始してください。このリンクはhttp://stackoverflow.com/questions/37938771/uilocalnotification-is-deprecated-in-ios10に役立ちます – miOS

答えて

0
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) 
{ 
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories:nil]; 
    [application registerUserNotificationSettings:settings]; 
} 
関連する問題