2017-08-09 114 views
0

在我的應用程序中,您可以選擇觀看某個特定區域。當跨越邊界時,會發出通知。應用程序處於前景時的alertView和聲音,以及應用程序處於後臺時的警報聲通知。當應用程序在前臺時,一切都很好。在後臺進行時,不會發出通知,也不會播放鬧鐘聲。它以前工作得很好。警報(通知)聲音在iOs中突然停止工作

這裏是我的代碼:

// Show alertview when active and show localNotification when inactive 

-(void)AlertViewShow{ 

    if (i == 1) { 

    UIAlertView *alert = [[UIAlertView alloc] 
          initWithTitle:NSLocalizedString (@"Alert",@"") 
          message:NSLocalizedString(@"AlertMoving",@"") 
          delegate:self 
          cancelButtonTitle:NSLocalizedString(@"AlertOK",@"") 
          otherButtonTitles:nil]; 

    [alert show]; 

    NSURL *soundURL = [[NSBundle mainBundle]URLForResource: @"ALARM" 
              withExtension:@"WAV"]; 
    avSound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:nil]; 
    avSound.numberOfLoops = -1; 
    [avSound play]; 
} 
i = 2; 
} 


- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { 
if (buttonIndex == 0) { 
    if ([avSound isPlaying]) { 
     [avSound stop]; 
    } 
} 
if (i == 2) { 
    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 

} 

} 

- (void)localNotification { 

UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 

if (localNotif == nil) 
    return; 
localNotif.fireDate = nil; 
localNotif.alertBody = NSLocalizedString (@"NotifAlert",@""); 
localNotif.alertAction = NSLocalizedString (@"NotifView",@""); 
localNotif.soundName = @"ALARMSHORT.wav"; 
localNotif.applicationIconBadgeNumber = 0; 

[[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 

} 

// END Show alertview when active and show localNotification when inactive 

有誰知道什麼改變,爲什麼它突然不工作了? 感謝您的幫助。

+0

「之前」是什麼意思?它停止在新設備上工作了嗎?也許這是iOS版本? – phi

+0

@phi,謝謝你的回覆。 '之前'我所說的是,它已經在我的設備和客戶設備上運行。現在我得到了一份報告,它不起作用,在我的設備上iPhone 6s plus與iOs 10.3.3不兼容。我之前沒有注意到這一點,因此這個問題有可能會延長一段時間。看起來,當新的iOs版本發佈時,我沒有做足夠的測試。對我感到羞恥。我不是一個非常熟練的開發人員。這個項目是一個計時器,但現在我遇到了麻煩,因爲有數千次安裝。所以你的幫助非常感謝。 – A3O

+0

如果我是你,我的首要任務就是嘗試並重現錯誤。確保你瞭解它在哪種情況下發生。對我而言,您發佈的代碼似乎與該問題無關。 – phi

回答

0

您正在使用scheduleLocalNotification:deprecated in iOS 10。嘗試更新至UNUserNotificationCenter並查看您的問題是否仍然存在。

+0

謝謝,但你能告訴我該怎麼做嗎?對不起,我感覺很蠢,但看起來我完全迷失了,不知道該怎麼做...... :-(對我來說真是太可惜了...... – A3O