2017-08-09 115 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