0
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; 
    content.sound = [UNNotificationSound defaultSound]; 
    NSDateComponents *components = [[NSDateComponents alloc] init]; 
    components.hour = 0; 
    UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:YES]; 
    UNNotificationRequest *notificationRequest = [UNNotificationRequest requestWithIdentifier:kUserNotificationTag content:content trigger:trigger]; 
    [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:notificationRequest withCompletionHandler:nil]; 

Это мой код, чтобы получить возможность отправлять местное уведомление iOS10.When я поставил звукКак опубликовать локальное уведомление без звука в iOS 10?

[UNNotificationSound defaultSound] 

или

[UNNotificationSound soundNamed:@""] 

звук уведомления одновременно звука по умолчанию.

, но если я не настроил звук, местное уведомление не будет работать.

У кого-нибудь есть идеи? Большое спасибо!

+0

Вы удалили UIRemoteNotificationTypeSound из registerForRemoteNotificationTypes? –

+0

Нет, это не нужно. Я просто удаляю '' '' 'UNNotificationPresentationOptionSound'''' в завершенииHandler, как этот' '' 'completeHandler (UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert)' '' ', и решить эту проблему –

ответ

0

Нет, вы не можете отключить звук, потому что UILocalNotification не предоставляет никаких параметров для этого. Таким образом, лучший вариант - вы можете добавить пустой звуковой файл в свой комплект приложений и использовать его.

Подробнее вы можете refer here

+1

большое вам спасибо. Это экономит мое много времени ~ –

+0

Я удаляю UNNotificationPresentationOptionSound в завершенииHandler как это завершениеHandler (UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert) в центре '' '' - (void) jpushNotificationCenter: (UNUserNotificationCenter *) center будетPresentNotification: (UNNotification *) уведомление сCompletionHandler: (void (^) (NSInteger)) завершениеHandler'''' и решить эту проблему в некотором роде –