Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS中实现本地通知?_Ios_Localnotification - Fatal编程技术网

如何在iOS中实现本地通知?

如何在iOS中实现本地通知?,ios,localnotification,Ios,Localnotification,我正在尝试在特定时间实现本地通知调用。这是我的密码。如果我做错了,请帮助我。 在.m文件中 NSDateComponents* deltaComps = [[NSDateComponents alloc] init] ; [deltaComps setDay:1]; NSDate* tomorrow = [[NSCalendar currentCalendar] dateByAddingComponents:deltaComps toDate:[NSDate

我正在尝试在特定时间实现本地通知调用。这是我的密码。如果我做错了,请帮助我。
在.m文件中

NSDateComponents* deltaComps = [[NSDateComponents alloc] init] ;
         [deltaComps setDay:1];
         NSDate* tomorrow = [[NSCalendar currentCalendar] dateByAddingComponents:deltaComps toDate:[NSDate date] options:0];


        //
      //  NSDate *date = [NSDate date];
       NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
       // NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit)
       //                                                fromDate:tomorrow];

        NSDateComponents *temp = [[NSDateComponents alloc]init];

        [temp setYear:2014];
        [temp setMonth:8];
        [temp setDay:21];
        [temp setHour: 13];
        [temp setMinute:38];

        NSDate *fireTime = [calendar dateFromComponents:temp]; // December 31st 2013 9:00


        // set up the notifier
        UILocalNotification *localNotification = [[UILocalNotification alloc]init];

        localNotification.fireDate = fireTime;
        localNotification.timeZone = [NSTimeZone systemTimeZone];
        localNotification.alertBody=@"Nishant";
        localNotification.alertAction = NSLocalizedString(@"Show", nil);
        localNotification.soundName = @"Gentle Rise.m4a";
        localNotification.hasAction = YES;
并在应用程序代理文件中接收通知文件

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
   // NSLog(@"%@", notification);
}

请告诉我哪里做错了。任何帮助都将不胜感激。

您在哪里安排通知

e、 g-

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

localNotification在您安排之前不会出现。

您在哪里安排
UILocalNotification
?您需要通过
[[UIApplication sharedApplication]presentLocalNotificationNow:localNotification]来计划它感谢您的帮助@rckoenes