2012-03-25 2 views
1

기도 시간을 생성하는 앱 (하루에 5 번) 5 가지기도에 대한 알림을 만들고 싶지만 일부 계산을 기준으로 매일 바뀌는 문제입니다.서로 다른 시간에 지역 알림 반복

편집 :

계산이 다른 도시에 대한 사용자 변경 사항이 시간이 따라 업데이트 할 수 있도록 GPS 위치를 기반으로 수행됩니다. 나는 날짜, 시간대를 입력하고, GPS 좌표로 좌표를 매기고 그 주어진 날/위치에 대한기도 시간 값을 (HH : mm) 형식으로 얻는다. 이제 Notfications를 설정해야합니다. 나는 그들을 어디에 둘 것인지 확실하지 않다.

여기에 코드

#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 
+0

일부 코드보기 (예 : 계산) – keyser

+0

그냥 5 개의 알림 추가 – NeverBe

+0

시간을 계산하는 방법이나 'UILocalNotification'을 예약하는 방법에 대한 질문이 있습니까? –

답변

2

당신은, 당신의 다섯 알림을 반복 그들이 매일 같은 시간에 표시하기 위해 repeatInterval 매개 변수를 사용할 수 있습니다. 불행히도 앱을 실행하지 않고 시간을 조정할 방법이 없습니다.

백그라운드에서 GPS 앱을 실행합니다. 일부 타이머 설정을 위해 배터리가 상당히 소모 될 수 있습니다. (이 백그라운드 프로세스는 GPS 추적기 앱을 위해 고안된 것이며, 약간 다른 목적으로 Apple이 사용하게 될 것이 무엇인지 잘 모르겠습니다.) 그러나 앱을 시작할 때 가장 쉬운 방법은 업데이트하는 것입니다. 실행될 때 (의 scheduledLocalNotifications 속성을 사용하는) 현재 알림을 얻고, 올바르지 않거나 오래되어 새로운 항목을 만들면 취소합니다. 각 알림에는 사전 확인로드가있어 경보를 쉽게 식별 할 수 있습니다.

+0

문제는이 시간이 예를 들어 어느 날 오전 4시 30 분에 문제가되지 않는다는 것입니다. 한 달이 더 증가 할 것이고 그 다음 해의 어떤 시점에서 태양의 일출과 일몰과 그로 인한 일일 변화와 관련이 있습니다. – M7ammed

+0

나는 나의 마지막 단락을 소개합니다. iOS에는 백그라운드에서 임의의 앱을 실행할 수있는 방법이 없습니다. 또는 푸시 알림 (예 : 서버)을 고려할 수도 있지만 GPS의 변경 사항을 사용하여 서버가 어디에 있는지 알려줄 수 있습니다. 물론 프라이버시 고려 사항이있을 수 있습니다. –

+0

좋아, 그래서 내가보기에로드 알림 않았 설치해야 응용 프로그램이 출시됩니다, 그것을 갱신 할 것이라고? 사용자가 앱을 방문 할 때마다 notfication을 설정하지 않도록하려면 어떻게해야합니까? 이미 알림이 설정되지 않았습니까? – M7ammed