변경 사항이있을 때 내 앱이 이메일 서버를 폴링하고 현지 알림을 보내는 백그라운드에서 실행하게합니다. 백그라운드 상태에서 알림을 시작할 수는 있지만 휴대 전화가 진동하면 오디오가 재생되지 않습니다. 진동이 켜져있을 때 시계 앱의 알람이 계속 울리는 방식을 무시하는 방법이 있습니까? 내가 경고로드휴대 전화가 진동 할 때 알림 음 재생
+ (void)initializeAudioSettings
{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
if (!success) {
NSLog(@"Error setting up Audio session: %@", setCategoryError.description);
}
NSError *activationError = nil;
success = [audioSession setActive:YES error:&activationError];
if (!success) {
NSLog(@"Error setting audio session active: %@", activationError.description);
}
}
다음 : 발사에 내 응용 프로그램 위임에
, 내가 아래에있는 내 경고의 클래스 메소드는 백그라운드에서 재생을 위해 설정하는 전화를 그런
- (void)loadAlertSoundID
{
NSLog(@"Loading alert sound");
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"alert" ofType:@"mp3"];
NSURL *soundURL = [NSURL URLWithString:soundPath];
CFURLRef url = (__bridge CFURLRef)soundURL;
AudioServicesCreateSystemSoundID(url, &_alertSoundID);
}
을 때 새 메시지를 알리는 경우 알림 방법을 호출합니다.
- (void)playAlert
{
NSLog(@"Playing alert");
AudioServicesPlaySystemSound(_alertSoundID);
_alertShouldBePlaying = YES;
_alertIsPlaying = YES;
AudioServicesAddSystemSoundCompletion(_alertSoundID, nil, nil, playSoundFinished, (__bridge void*)self);
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(vibrate:) userInfo:nil repeats:YES];
}
그리고 완성을 위해 blo 사례 :
void playSoundFinished (SystemSoundID sound, void *data)
{
Alert *alert = [Alert sharedAlert];
if (sound == alert.alertSoundID)
{
alert.alertIsPlaying = NO;
// Repeat until alert is disabled
if (alert.alertShouldBePlaying && !alert.alertIsPlaying)
{
[alert playAlert];
}
}
}
이것은 "극장 밖으로 던져 버려"기능입니다. –
저는 사무실에서 내부적으로 사용할 도구로 이것을 구축하고 있습니다. 작업을 시작한 다음 날에는 진동으로 전환 한 다음 자동으로 업무에 복귀하는 "근무 외 근무"옵션이 있습니다. – Chris
진동에 전화를 걸면 소리가 나지 않습니다. – rmaddy