2011-11-02 2 views
0

알림 사운드는 20 초입니다 만, 그 사운드를 적어도 60 초 후에 반복하고 싶습니다. 내 소중한 코드는 다음과 같습니다 ...어떻게 "보기"버튼을 누를 때까지 내 로컬 알림 사운드를 반복 할 수 있습니까?

코드를 살펴보고 좀 도와주세요 D : -.

@interface SetAlarmViewController : UIViewController <UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>{ 

    IBOutlet UITableView *tableview; 
    IBOutlet UIDatePicker *datePicker; 
    IBOutlet UITextField *eventText; 

    IBOutlet UINavigationBar *titleBar; 
    IBOutlet UIButton *setAlarmButton; 
} 

@property (nonatomic, retain) IBOutlet UITableView *tableview; 
@property (nonatomic, retain) IBOutlet UIDatePicker *datePicker; 
@property (nonatomic, retain) IBOutlet UITextField *eventText; 

@property(nonatomic, retain) IBOutlet UINavigationBar *titleBar; 
@property(nonatomic, retain) IBOutlet UIButton *setAlarmButton; 
@property(nonatomic) UIReturnKeyType returnKeyType; 

- (IBAction) scheduleAlarm:(id) sender; 
- (void)showReminder:(NSString *)text; 


@implementation SetAlarmViewController 
@synthesize datePicker,tableview, eventText,titleBar,setAlarmButton,returnKeyType; 


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    eventText.returnKeyType = UIReturnKeyDone; 

    datePicker.minimumDate = [NSDate date]; 
    NSDate *now = [NSDate date]; 
    [datePicker setDate:now animated:YES]; 

    eventText.delegate = self; 
} 

- (void) viewWillAppear:(BOOL)animated { 
    [self.tableview reloadData]; 
} 

- (IBAction) scheduleAlarm:(id) sender { 
    [eventText resignFirstResponder]; 
    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; 

    // Get the current date 
    NSDate *pickerDate = [self.datePicker date]; 

    // Break the date up into components 
    NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) 
                fromDate:pickerDate]; 
    NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) 
                fromDate:pickerDate]; 
    // Set up the fire time 
    NSDateComponents *dateComps = [[NSDateComponents alloc] init]; 
    [dateComps setDay:[dateComponents day]]; 
    [dateComps setMonth:[dateComponents month]]; 
    [dateComps setYear:[dateComponents year]]; 
    [dateComps setHour:[timeComponents hour]]; 
    // Notification will fire in one minute 
    [dateComps setMinute:[timeComponents minute]]; 
    [dateComps setSecond:[timeComponents second]]; 
    NSDate *itemDate = [calendar dateFromComponents:dateComps]; 
    [dateComps release]; 

    UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
    if (localNotif == nil) 
     return; 
    localNotif.fireDate = itemDate; 
    localNotif.timeZone = [NSTimeZone defaultTimeZone]; 

    // Notification details 
    localNotif.alertBody = [eventText text]; 

    // Set the action button 
    localNotif.alertAction = @"Show me"; 
    localNotif.repeatInterval = NSDayCalendarUnit; 
    localNotif.soundName = @"jet.wav"; 
    localNotif.applicationIconBadgeNumber = 1; 

    // Specify custom data for the notification 
    NSDictionary *userDict = [NSDictionary dictionaryWithObject:eventText.text 
                 forKey:kRemindMeNotificationDataKey]; 
    localNotif.userInfo = userDict; 

    // Schedule the notification 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
    [localNotif release]; 

    [self.tableview reloadData]; 
    eventText.text = @""; 
} 

#pragma mark - 
#pragma mark Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [[[UIApplication sharedApplication] scheduledLocalNotifications] count]; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications]; 
    UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row]; 
    if(notif) 
    { 
     [[UIApplication sharedApplication] cancelLocalNotification:notif]; 
    } 

    [self.tableview reloadData]; 
} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell... 

    NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications]; 
    UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row]; 

    [cell.textLabel setText:notif.alertBody]; 
    [cell.detailTextLabel setText:[notif.fireDate description]]; 

    return cell; 
} 

- (void)viewDidUnload { 
    datePicker = nil; 
    tableview = nil; 
    eventText = nil; 
    [super viewDidUnload]; 

} 

#pragma mark - 
#pragma mark === Text Field Delegate === 
#pragma mark - 

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 

    [textField resignFirstResponder]; 
    return YES; 
} 


#pragma mark - 
#pragma mark === Public Methods === 
#pragma mark - 

- (void)showReminder:(NSString *)text { 

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Reminder" 
                 message:text delegate:self 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 
    [alertView show]; 
    [self.tableview reloadData]; 

    [alertView release]; 
} 


- (void)dealloc { 
    [super dealloc]; 
// [datePicker release]; 
// [tableview release]; 
// [eventText release]; 
} 

@end 
+0

@chown : 나는 이것을 처음 접했고 무엇을 수정 했는가 ...? :) – mAc

+0

코드 형식을 1 줄만 고정했습니다. '@ end'는 4 칸 들여 쓰기되지 않았습니다. :) – chown

+0

그 덕분에 고마워 ... 내 질문에 관한 어떤 추측도 .. ?? – mAc

답변

1

그냥 fireDate>= 60 때문에 총 시간까지 the sound's duration의 간격으로 여러 지역 알림을 예약하는 경우 그들이 다시 무시하고 다시 꺼내고 사용자가 Show Me을 누르면 unsche 앱 실행시이 이벤트에 대한 나머지 알림을 남기십시오.

남은 유일한 문제는 Close을 누르면 어떻게됩니까? 나는 당신이 할 수 있도록 콜백되어야 할 것 같아요 뭔가 때 알림이 닫혀 .. 맞습니까? (지금 당장은 못 찾겠다)

+0

@darvidsOn : - 고마워요, 사실 나는 여러 알림 (128 개까지 제공 할 수 있음)을 제공해야한다는 사실을 발견했습니다. 나는이 모든 것을 구현하는 방법을 여전히 생각하고 있습니다. 당신의 제안은 또한 좋습니다. 시도해 봅니다. 제 일을한다면 답을 기꺼이 받아 들일 것입니다. 감사 – mAc

관련 문제