我有一个应用程序,生成祈祷时间(每天5次),我想为5个祈祷创建注释,但问题是,根据一些计算,时间每天都会改变。
编辑:
计算是基于GPS位置完成的,因此当用户更改到另一个城市时,时间会相应地更新。我将日期、时区、GPS坐标输入到一个方法中,并获得该给定日期/地点的(HH:mm)格式的祈祷时间值。现在我需要设置通知。我不知道该把它们放在哪里。
以下是代码
#import "PrayerTimeViewController.h"
#import "PrayTime.h"
@implementation PrayerTimeViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
UITabBarItem *tbi = [self tabBarItem];
[tbi setTitle:NSLocalizedString(@"PrayerTimes", nil)];
UIImage *i = [UIImage imageNamed:@"11-clock"];
[tbi setImage:i];
[i release];
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Madinah"]];
self.view.backgroundColor = background;
[background release];
locationManager = [[CLLocationManager alloc]init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager startUpdatingLocation];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSTimeInterval t = [[newLocation timestamp] timeIntervalSinceNow];
if (t < -180) {
return;
}
PrayTime *prayerTime = [[PrayTime alloc]init];
[prayerTime setCalcMethod:0];
[prayerTime setFajrAngle:16];
[prayerTime setIshaAngle:14];
[prayerTime setAsrMethod:0];
NSDate *curentDate = [NSDate date];
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* compoNents = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:curentDate];
CLLocationCoordinate2D currLoc = [newLocation coordinate];
NSMutableArray *prayerCal = [prayerTime getDatePrayerTimes:[compoNents year] andMonth:[compoNents month] andDay:[compoNents day] andLatitude:currLoc.latitude andLongitude:currLoc.longitude andtimeZone:[[NSTimeZone localTimeZone] secondsFromGMT]/3600];
[prayerTime release];
[fajer setText:[prayerCal objectAtIndex:0]];
// UILocalNotification *localNotification = [[UILocalNotification alloc] init];
NSString *time = [prayerCal objectAtIndex:0];
NSString *dates = [NSString stringWithFormat:@"%d-%d-%d %@",[compoNents year],[compoNents month],[compoNents day],time];
NSDateFormatter *dateText = [[NSDateFormatter alloc]init];
[dateText setDateFormat:@"yyyy-MM-dd HH:mm"];
[dateText setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:[[NSTimeZone localTimeZone] secondsFromGMT]]];
NSLog(@"%@",[dateText dateFromString:dates]);
[shrooq setText:[prayerCal objectAtIndex:1]];
[duhur setText:[prayerCal objectAtIndex:2]];
[aser setText:[prayerCal objectAtIndex:3]];
[maghreb setText:[prayerCal objectAtIndex:5]];
[isha setText:[prayerCal objectAtIndex:6]];
[prayerCal release];
}
@end
https://stackoverflow.com/questions/9862261
复制相似问题