Cal*_*her 5 push-notification xamarin.ios apple-push-notifications ios
我可以成功注册我的应用程序进行推送通知:
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(
UIRemoteNotificationType.Alert
| UIRemoteNotificationType.Badge
| UIRemoteNotificationType.Sound);
Run Code Online (Sandbox Code Playgroud)
但每当我执行此操作时,我的UI通常会挂起2-3秒.即使我在应用程序生命周期的早期按照推荐(例如,偶数WillFinishLaunching),在我的第一个ViewController加载后,我的UI仍然会挂起.
我的第一个想法是在一个单独的线程中执行注册,但MonoTouch阻止了这个:
// From MonoTouch.UIKit
public virtual void RegisterForRemoteNotificationTypes(UIRemoteNotificationType types)
{
UIApplication.EnsureUIThread();
Run Code Online (Sandbox Code Playgroud)
我的下一个想法是至少弹出一个UIAlertView盒子让用户知道正在发生的事情,但由于某种原因它直到注册发生后才显示,导致UIAlertView开放并立即关闭!
modalPopup = new UIAlertView("Working", "The application is loading...", null, null);
modalPopup.Show();
// It doesn't show here!
RegisterForRemoteNotificationTypes();
// It shows here!
modalPopup.DismissWithClickedButtonIndex(0, true);
Run Code Online (Sandbox Code Playgroud)
我怎么能
您是否覆盖了 public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
或者
公共覆盖无效FailedToRegisterForRemoteNotifications(UIApplication应用程序,NSError错误)
我也遇到过类似的问题,在 Registered... 函数中,我调用了一个 Web 服务来上传设备令牌。但网络调用不在另一个线程中,因此导致 UI 冻结。
| 归档时间: |
|
| 查看次数: |
503 次 |
| 最近记录: |