2013-05-28 56 views

回答

1

没有本地通知到期的概念。你告诉他们开火,并由用户来解雇或与他们互动。

关于使声音持续20秒(除了事实上我会删除这个应用程序,如果它坚持播放20通知声音!),让我们说,例如,你当前的声音持续5秒,你可以复制粘贴在一个文件中发声4次,然后播放。我认为最大声音长度为30秒,但我无法找到支持这一点的文档。

+0

他实际上可能使一个短的蜂鸣声与无声19secs如果这是真的,该通知停留在屏幕只要声音正在播放... –

+0

问题是,这不是真正的Engin。它一直保持在屏幕上,直到用户与其交互为止,这可能是永远的。 –

0

您可以通过在每20秒后更改notify.firedate来设置持续时间。

维持每20秒 - 您可以使用定时器

1

对不起,我的英语不好。 您只能使用NSCalendarUnit值重复本地通知。或重置他(通知),并设置新的旧通知在方法(应用程序:didReceiveLocalNotification :)工作。为此,您可以将自己的字典添加到通知对象userInfo值,并在稍后在此方法中收到通知时处理它。但是,当应用程序未运行时,此方法无法在后台模式下运行,或者未点击通知警报运行。希望这可以帮助。

0

如果它是关于重复的通知声音,那么你可以这样做:

UILocalNotification* notifyAlarm =[[UILocalNotification alloc] 
             init]; 
    if (notifyAlarm) 
    { 
     notifyAlarm.timeZone = [NSTimeZone defaultTimeZone]; 
     notifyAlarm.fireDate = nil; 
     [email protected]"phone.wav"; 
     notifyAlarm.alertBody [email protected]"value"; 
     [email protected]"value"; 
     notifyAlarm.hasAction=YES; 
     [[UIApplication sharedApplication] presentLocalNotificationNow:notifyAlarm]; 
     [notifyAlarm release]; 

     UIApplicationState state = [[UIApplication sharedApplication] applicationState]; 
     if (state == UIApplicationStateInactive || state==UIApplicationStateBackground) { 
      [self backgroundHandlerToPlayCallTone]; 
     } 
    } 

-(void)backgroundHandlerToPlayCallTone { 
UIApplication* app = [UIApplication sharedApplication]; 
bgTaskToPlayCallTone = [app beginBackgroundTaskWithExpirationHandler:^{ 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     [app endBackgroundTask:self->bgTaskToPlayCallTone]; 
     self->bgTaskToPlayCallTone = UIBackgroundTaskInvalid; 
    }); 
}]; 

// Start the long-running task 
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{ 
//dispatch_async(dispatch_get_main_queue(), ^{ 
    [self startCallTone]; 
    [app endBackgroundTask:self->bgTaskToPlayCallTone]; 
    self->bgTaskToPlayCallTone= UIBackgroundTaskInvalid; 
}); 
} 

-(void) startCallTone { 
if(audioPlayer !=nil) { 
    [audioPlayer pause]; 
    [audioPlayer release]; 
    audioPlayer=nil; 
} 
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"phone" ofType:@"wav"]]; 
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; 
[audioPlayer setDelegate:self]; 
audioPlayer.numberOfLoops=10; 
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; 
//[[AVAudioSession sharedInstance] setActive:YES withFlags:AVAudioSessionSetActiveFlags_NotifyOthersOnDeactivation error:nil]; 
UInt32 allowMixing = true; 
AudioSessionSetProperty (kAudioSessionProperty_OtherMixableAudioShouldDuck, sizeof(allowMixing),&allowMixing); 

[[AVAudioSession sharedInstance] setActive: YES error: nil]; 
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 
[audioPlayer play]; 
} 
相关问题