繁体   English   中英

发出本地警报通知

[英]Make Local Alert Notification

我正在使用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();

使用[notification setSoundName:UILocalNotificationDefaultSoundName]; 它将正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM