【问题标题】:Xamarin Forms iOS Device won't receive Push from Urban AirshipXamarin Forms iOS 设备将不会收到来自 Urban Airship 的推送
【发布时间】:2017-03-02 15:25:32
【问题描述】:

我有一个 Xamarin Forms 应用程序,我无法在 iOS 中获得推送通知。他们在 Android 中运行良好。该设备正在使用其 SDK v4.1.0 正确注册到 Urban Airship。我能够获得 ChannelId 和设备令牌。当我在 Dev 通道上发送推送时,Android 设备会收到通知,但 iOS 设备不会。在 Urban Airship 中,完整消息报告显示消息已发送到 Android 设备以及我测试过的两台 iOS 设备。我确定我错过了一些小东西,但我无法弄清楚它是什么。以下是来自 App Delegate 的源代码作为参考。从我看到的例子来看,这很简单。

using System;
using System.Collections.Generic;
using System.Linq;

using Foundation;
using UIKit;
using UrbanAirship;

namespace -----------.Mobile.iOS
{
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();

            UAConfig config = new UrbanAirship.UAConfig();
            config.DevelopmentAppKey = "----------------------";
            config.DevelopmentAppSecret = "----------------------";
            config.ProductionAppKey = "----------------------";
            config.ProductionAppSecret = "----------------------";

#if DEBUG
            config.InProduction = false;
#else
            config.InProduction = true
#endif
            UAirship.TakeOff(config);
            UAirship.Push.UserPushNotificationsEnabled = true;
            UAirship.Push.ChannelTagRegistrationEnabled = true;

            // Write the ChannelId for reference later.

            Guid urbanAirshipChannelId;
            UrbanAirshipData uaData = new UrbanAirshipData();
            if (Guid.TryParse(UAirship.Push.ChannelID, out urbanAirshipChannelId))
            {   
                uaData.UrbanAirshipChannelId = urbanAirshipChannelId;
                uaData.UrbanAirshipDeviceType = Common.Utilities.Enumerations.eUrbanAirshipDeviceType.iOS;
            }
            UAirship.Push.PushNotificationDelegate = PushReceived();


            LoadApplication(new App(uaData));

            return base.FinishedLaunching(app, options);
        }

        private UAPushNotificationDelegate PushReceived()
        {
            UAPushNotificationDelegate result = new UAPushNotificationDelegate();

            return result;
        }



    }
}

任何反馈或想法将不胜感激。

【问题讨论】:

    标签: ios xamarin xamarin.forms urbanairship.com


    【解决方案1】:

    UAirship.Push.PushNotificationDelegate = PushReceived(); 行,Urban Airship 的代表存在一个问题,他们没有存储对代表的强引用 - https://github.com/urbanairship/xamarin-component/issues/40

    但是,这不会导致设备无法接收推送。默认情况下,如果应用程序在前台,推送接收不会发生任何事情。在后台它会发布一个通知。您可以通过在 iOS 10 的 UAPush 实例上设置默认前台通知选项来修改该行为。

    如果您仍然难以收到推送,我会联系 Urban Airships 支持或在 github 上发布问题。需要完整的日志。

    【讨论】:

    • 感谢您的回复。我有个问题。 iOS 中的预期行为是否如下?当应用程序在前台运行并收到推送时,该设备不会通知用户,但通知会与其他通知一起列出?此外,您提到这可以在 UAPush 实例中更改。当我尝试推送时,我一直在看通知列表,但什么也没看到。我想我可能不得不发布一个问题。我已经联系了 UA,但是我们客户的服务级别没有支持。
    • Apple 假设应用程序将处理推送,并且在 iOS 10 之前不会发布任何通知。现在他们允许设置前台演示选项。您可以在此处设置默认值 - docs.urbanairship.com/reference/libraries/ios/latest/Classes/…。他们可能会让您在社区论坛上发帖,但他们会很快回复。
    • 谢谢。我将把它作为我的下一步。感谢您的反馈。
    • 我如何获得在 Urban Airship 上发布所需的完整日志。
    • 通过在您的飞艇配置选项中设置日志级别来启用详细日志记录。然后复制控制台输出。确保您没有发布您的应用凭据或任何私人信息。
    【解决方案2】:

    对我来说,问题在于我在前台使用应用程序进行测试,而 iOS 没有在应用程序运行时显示通知。我必须添加以下内容才能让它在前台工作并发出声音。

    UAirship.Push.DefaultPresentationOptions = UserNotifications.UNNotificationPresentationOptions.Alert | UserNotifications.UNNotificationPresentationOptions.Sound;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多