此视频是一个应用程序的记录,它可以
- 超越静音模式
- 覆盖锁定屏幕
- 播放闹钟音乐/旋律
我们的团队正在开发一个类似的定制 iphone 闹钟
如果有人可以提供帮助,我将不胜感激。我一直试图打破这个两周。
当设备被锁定时,我们下面的方法不会被调用。这就是为什么没有播放警报声的原因
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
if ([GlobalData gSettings].vibration) {
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
isVibration = YES;
} else {
isVibration = NO;
}
self.uinfo = notification.userInfo;
NSString *soundname = [uinfo objectForKey:@"sound"];
NSURL *clip = [[NSBundle mainBundle] URLForResource:soundname withExtension:@"caf"];
if (clip) {
self.avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:clip error:NULL];
self.avPlayer.delegate = self;
AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
// Allow playback even if Ring/Silent switch is on mute
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory),&sessionCategory);
}
else
{
NSURL *clip = [[NSUserDefaults standardUserDefaults]URLForKey:[uinfo objectForKey:@"sound"]];
self.avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:clip error:NULL];
self.avPlayer.delegate = self;
AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
// Allow playback even if Ring/Silent switch is on mute
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory),&sessionCategory);
}
[self.avPlayer play];