0

本周我通过几个绑定库将 IntercomIO SDK 添加到了我们的 Xamarin.Forms 应用程序中,我目前正在尝试让推送通知工作,但在 MainActivity 中调用 PushHandlerService.Register(this) 后不久,应用程序崩溃说它找不到类 com.google.android.gms.gcm.GcmReceiver 甚至没有被这个调用周围的 try catch 块捕获。

这是 MainActivity 中负责在 Android 上设置推送通知的方法。

    public void registerForPushNotifications()
    {
        try
        {
            GcmClient.CheckDevice(this);
            GcmClient.CheckManifest(this);

            //Register the app for push notifications.
            PushHandlerService.Initialize(this);

            //if (!GcmClient.IsRegistered(this))//Temporarily force the app to register for push notifications
            {
                System.Diagnostics.Debug.WriteLine("Registering");

                // Register for GCM
                PushHandlerService.Register(this);
            }

            LocalBroadcastManager lbc = LocalBroadcastManager.GetInstance(this);
            PushActionReceiver rec = new PushActionReceiver(this);
            lbc.RegisterReceiver(rec, new IntentFilter("pushaction"));
        }
        catch (Java.Net.MalformedURLException)
        {
            var e = new Exception("There was an error creating the Mobile Service. Verify the URL");
            System.Diagnostics.Debug.Fail(String.Format(@"Exception at {0}: {1}", this.GetType().Name, e.Message));
            Insights.Report(e);
        }
        catch (Exception e)
        {
            System.Diagnostics.Debug.Fail(String.Format(@"Exception at {0}: {1}", this.GetType().Name, e.Message));
            if (e.GetType() != typeof(TaskCanceledException))
                Insights.Report(e);
        }
    }

在清单中,我添加了对讲机的接收器定义

<receiver android:name="io.intercom.android.sdk.gcm.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"></receiver>

当我不调用 PushHandlerService.Register(this) 时,问题不会发生,但显然我无法再收到任何推送通知(包括来自我们自己系统的推送通知)

这里发生了什么?我正确设置了库和依赖项,但似乎无法找到 GcmReceiver 类..

4

2 回答 2

1

显然在 SDK 管理器中更新到最新的 SDK 解决了这个崩溃。我仍然没有收到任何推送通知,但我猜这是由于另一个问题。至少该应用程序在尝试注册推送通知时不再崩溃。

于 2016-09-23T14:27:18.383 回答
0

对讲机的戴尔在这里。您是否在使用任何其他第三方推送提供商,或者您是否拥有自己的 GCM 接收器?他们可能正在消耗我们的推动力而不是传递它们。这在 Xamarin、Phonegap、Cordova 等中可能很困难。注册和接收服务通常不可用。我在下面包含了指向我们的 GCM 文档的链接以及可能与您最相关的部分。如果这无助于解决问题,请通过cordova repo 与我们联系:https ://github.com/intercom/intercom-cordova或在您的对讲仪表板中与我们联系/发送电子邮件至 team@intercom.io .

我们在这里有 GCM 文档:https ://docs.intercom.com/configure-intercom-for-your-product-or-site/configure-intercom-for-mobile/enable-push-notifications-with-intercom-for-安卓-gcm

可能导致您设置困难的问题是:

步骤 7. 将对讲机与其他 GCM 设置一起使用(可选)

这仅适用于也将 GCM 用于自己的内容的应用程序,或将第三方服务用于 GCM 的应用程序。您需要更新 GcmListenerService 和生成设备令牌的类。

您应该有一个生成推送设备令牌并将其发送到后端的类。除了将令牌发送到您的后端之外,您还需要将其转发到对讲机,如下所示:

private final IntercomPushClient intercomPushClient = new IntercomPushClient();

public void onHandleIntent(Intent intent) {     
    InstanceID instanceId = InstanceID.getInstance(this);
    String senderId = "YOUR_SENDER_ID";
    String token = instanceId.getToken(senderId,
    GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
    pushClient.sendTokenToIntercom(getApplication(), token);
}

您应该有一个扩展 GcmListenerService 的类。该服务将消耗用于 Intercom 的推送。为了让我们绘制对讲推送,请设置您的 GcmListenerService,如下所示:

private final IntercomPushClient intercomPushClient = new IntercomPushClient();

public void onMessageReceived(String from, Bundle message) {
    if (intercomPushClient.isIntercomPush(message)) {
        intercomPushClient.handlePush(getApplication(), message);
    } else {
        //DO HOST LOGIC HERE
    }
}
于 2016-10-06T11:01:44.067 回答