2013-07-25 2 views
4

표시가없고 소리가 없지만 진동 만있는 로컬 알림을 원합니다. alertBody@""으로 설정하면 화면이 표시되지 않지만 어떻게 소리를 보낼 수 있습니까? 나는 너희들에게 더 좋은 길을 얻지 못한다면 나는 비어있는 소리를 내 프로젝트에 추가 한 다음 그 soundName을 그 소리로 설정할 수있을 것이라고 생각하고있다. 그러나 이것을하기위한 기본 방법이 있습니까?소리없이 로컬 알림을 보낼 수 있습니까?

가짜 사운드 이름을 추가하면 여전히 기본 알림 사운드가 재생됩니다.

감사합니다.

답변

3

아니요. UILocalNotification에서 옵션을 제공하지 않으므로 소리를 비활성화 할 수 없습니다. 그래서 빈 소리 파일을 사용하는 질문에 말한대로 더 나은 옵션입니다.

+0

잘못된 sound.or 설정할 수 없습니다! 사운드 파일없이 푸시 알림을받을 수 있습니다! http://stackoverflow.com/questions/9841600/ios-push-notifications-how-to-specify-alert-and-badge-with-no-sound –

+2

@GuntisTreulands는 먼저 질문을 올바르게 읽은 다음 대답을 주석으로 답니다. 질문은 Apple Push Notification이 아닌 UILocalNotification과 관련됩니다. –

+0

나쁘다! 죄송합니다. 다음 번에는 더 조심스럽게 읽을 것입니다. –

3

예. 다른 소리 파일을 추가 할 수 있습니다.

NSString *[email protected]"temp.mp3"; 

UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 
    if (localNotification==nil) { 
     return; 
    } 
    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60]; 
    localNotification.alertBody = @"Your alert message"; 
    localNotification.soundName = soundFile; 
    localNotification.timeZone = [NSTimeZone defaultTimeZone]; 

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

위 코드에서 "soundFile"문자열 대신 리소스에 저장 한 사운드 파일의 이름을 넣으십시오.

0

는 당신은

-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)responsewithCompletionHandler:(void (^)())completionHandler{ 
NSDictionary * userInfo = response.notification.request.content.userInfo; 
if([response.notification.request.trigger isKindOfClass:[UNCalendarNotificationTrigger class]]) {} 
else{} 
//don't write UNNotificationPresentationOptionSound 
completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge); 

}

관련 문제