我正在与Xamarin和iOS合作,但在通知方面我遇到了很多麻烦。我可以创建一个发送到通知中心的本地推送通知,但没有声音或指示通知实际到达。如何使通知成为警报通知,以便在进入通知中心之前显示在屏幕上?
以下是我目前通过以下方式生成通知的代码:
//create notification
var notification = new UILocalNotification ();
notification.AlertAction = "Open App";
notification.AlertTitle = "App";
notification.AlertBody = "There has been activity in the app";
notification.SoundName = UILocalNotification.DefaultSoundName;
//display notification
UIApplication.SharedApplication.ScheduleLocalNotification (notification);
编辑: 问题不仅仅是声音,而是没有收到警报的反馈,它只是静默地出现在通知中心。我也要求使用此代码的权限:
var settings = UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Alert
| UIUserNotificationType.Badge
| UIUserNotificationType.Sound,
new NSSet());
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
答案 0 :(得分:6)
使用 [notification setSoundName:UILocalNotificationDefaultSoundName]; 它会正常工作。