【问题标题】:Amazon SNS push notifications not handled when Xamarin.iOS app not runningXamarin.iOS 应用程序未运行时未处理 Amazon SNS 推送通知
【发布时间】:2014-10-17 13:30:23
【问题描述】:

我正在 Xamarin 中开发一个 iOS 应用程序,它需要通过 Amazon SNS 从我们现有的后台接收推送通知。

目前我正在使用亚马逊网页将测试通知发送到 APNS_SANDBOX。

我已经编写了代码并为 iOS 应用程序创建了证书,并且在应用程序运行时一切正常。但是,当应用程序处于后台或根本未加载时,iOS 设备不会收到任何通知。

在 Xamarin Studio 的项目选项中,我在后台模式下启用了以下功能 启用后台模式、后台获取、远程通知。 在 iOS 设备的常规设置中,后台应用刷新已在全局范围内为应用启用。

我想我一定错过了配置或苹果证书中的一些非常基本的东西,但我不知道是什么。

【问题讨论】:

    标签: xamarin.ios push-notification apple-push-notifications amazon-sns


    【解决方案1】:

    在阅读了各种 iOS/Objective C 问题的各种解决方案后,我设法找到了解决方案。正是这个特别的question 让我朝着正确的方向前进。 在 iOS 8.0 上运行时订阅推送通知的代码存在问题

    我的原始代码:

        public static void Subscribe()
        {
            if (UIDevice.CurrentDevice.SystemVersion [0] >= '8')
            {
                UIApplication.SharedApplication.RegisterForRemoteNotifications()
            }
            else
            {
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes (notificationTypes);
            }
        }
    

    我的新代码:

        public static void Subscribe()
        {
            if (UIDevice.CurrentDevice.SystemVersion [0] >= '8')
            {
                UIUserNotificationType types = UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert;
                UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes (types, null);
                UIApplication.SharedApplication.RegisterUserNotificationSettings (settings);
            }
            else
            {
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes (notificationTypes);
            }
        }
    

    此更改现在允许在应用处于后台或未运行时正确接收通知。

    【讨论】:

      猜你喜欢
      • 2018-11-14
      • 2012-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多