2016-12-14 1 views
0

내 코드UILocalNotification 트리거를 여러 번

-(void)notificationScheduler 
{ 
    UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 
    // localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:7]; 
    localNotification.alertBody = @"NPS message"; 
    localNotification.timeZone = [NSTimeZone defaultTimeZone]; 
    localNotification.soundName = UILocalNotificationDefaultSoundName; 
    localNotification.repeatInterval = 0; 
    //Setting badge 
    [UIApplication sharedApplication].applicationIconBadgeNumber += 1; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
} 

나는 버튼을 클릭 행동이 메서드를 호출하고 있습니다. 알림은 지속적으로 전화로 전달됩니다.

나는

- (void)application:(UIApplication *)application 
didReceiveLocalNotification:(UILocalNotification *)notification{ 
    NSLog(@"didReceiveLocalNotification"); 
    [application cancelLocalNotification:notification]; 

} 

하지만 didReceiveLocalNotification 메서드가 호출지고 있지 않은 알림을 중지하려면이 코드를 시도했다.

버튼 액션 코드

- (IBAction)btnSendClicked:(id)sender 
{ 

    [self notificationScheduler ]; 

    // saves in dB of sttarter and then reloads tableview to display the message. 

    if (![self.txtMessage.text isEqualToString:@""]) 
    { 
     // publish message 
     [objSttarter SttarterClassPublishTopic:strTopicIdToCompare strData:self.txtMessage.text]; 

     NSMutableDictionary *dctMessage = [[NSMutableDictionary alloc]init]; 
     [dctMessage setValue:@"message" forKey:@"type"]; 
     [dctMessage setValue:@"" forKey:@"timestamp"]; 
     [dctMessage setValue:@"You" forKey:@"from"]; 
     [dctMessage setValue:@"none" forKey:@"file_type"]; 
     [dctMessage setValue:@"" forKey:@"file_url"]; 
     [dctMessage setValue:@"False" forKey:@"sender"];// false = You sent a msg back. 

     NSMutableDictionary *dctPayload =[[NSMutableDictionary alloc]init]; 
     [dctPayload setValue:@"" forKey:@"title"]; 
     [dctPayload setValue:strTopicIdToCompare forKey:@"topic"];//* 
     [dctPayload setValue:self.txtMessage.text forKey:@"message"];//* 
     [dctMessage setValue:dctPayload forKey:@"payload"]; 

     [[DatabaseHandler sharedDatabaseHandler] insertDataToMessages:dctMessage]; 

//  NSIndexPath *path1 = [NSIndexPath indexPathForRow:arrmsg.count inSection:0]; 
//  NSArray *indexArray = [NSArray arrayWithObjects:path1,nil]; 
//  [arrmsg addObject:self.txtMessage.text]; 
//  [self.tableviewChat beginUpdates]; 
//  [self.tableviewChat insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationNone]; 
//  [self.tableviewChat endUpdates]; 
//  [self.view endEditing:YES]; 
//  [email protected]""; 

    self.txtMessage.text [email protected]""; 

    } 
} 
+0

이 'IBAction'은 'UIControlEventTouchUpInside' 이벤트에 의해 트리거된다는 것을 알고 있습니까? – siburb

+0

예, UIControlEventTouchUpInside에만 – vijeesh

답변

0

나는이에 AppDelegate에 didReceiveLocalNotification 코드를 변경하고 일했다.

- (void)application:(UIApplication *)application 
didReceiveLocalNotification:(UILocalNotification *)notification 
{ 
    NSLog(@"didReceiveLocalNotification"); 
    [application cancelLocalNotification:notification]; 
    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 


} 
+0

해결 방법이 있지만 해결 방법이 아닙니다. 다른 알림을 취소 할 필요는 없습니다. 알림을 실행하는 코드를 Google에 표시 할 수 있습니까? 예 : 버튼 누름 코드. – siburb

+0

@siburb 질문에 버튼 동작 코드를 추가했습니다. – vijeesh