Can I send a Local Notification with no sound?

大城市里の小女人 提交于 2019-11-29 13:56:28

No you can not disable sound because UILocalNotification does not provide any option for this. So better option is as you told in your question to use a empty sound file.

Yes you can add another sound file.

NSString *soundFile=@"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];

In above code just put the name of sound file which you have saved in your resources in place of "soundFile" string.

You can not set sound.or

-(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);

}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!