无法在 Xamarin 中与 IntercomIO 一起在 Android 上注册推送通知
Unable to register for push notifications on Android in Xamarin together with IntercomIO
这周我通过几个绑定库将 IntercomIO SDK 添加到我们的 Xamarin.Forms 应用程序中,我目前正在尝试让推送通知正常工作,但在我调用 PushHandlerService.Register(this ) 在 MainActivity 中,应用程序崩溃说它找不到 class 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 class..
显然在 SDK 管理器中更新到最新的 SDK 解决了这次崩溃。我仍然没有收到任何推送通知,但我猜这是由于其他问题造成的。至少应用程序在尝试注册推送通知时不会再崩溃。
来自 Intercom 的 Dale。您是否使用任何其他第三方推送提供商,或者您是否有自己的 GCM 接收器?他们有可能正在消耗我们的推动力而不是传递它们。这在 Xamarin、Phonegap、Cordova 等中可能很困难。通常注册和接收服务不可用。我在下面包含了我们的 GCM 文档和可能与您最相关的部分的 link。如果这不能帮助解决问题,请通过 cordova 存储库与我们联系:https://github.com/intercom/intercom-cordova 或在您的 Intercom 仪表板中联系我们/发送电子邮件至 team@intercom.io。
可能导致您设置困难的问题是:
第 7 步。将 Intercom 与其他 GCM 设置一起使用(可选)
这仅适用于为自己的内容也使用 GCM 或为 GCM 使用第三方服务的应用程序。您需要更新 GcmListenerService 和生成设备令牌的 class。
您应该有一个 class 来生成推送设备令牌并将其发送到您的后端。除了将令牌发送到您的后端之外,您还需要将其转发到 Intercom,如下所示:
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 的 class。该服务将消耗用于 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
}
}
这周我通过几个绑定库将 IntercomIO SDK 添加到我们的 Xamarin.Forms 应用程序中,我目前正在尝试让推送通知正常工作,但在我调用 PushHandlerService.Register(this ) 在 MainActivity 中,应用程序崩溃说它找不到 class 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 class..
显然在 SDK 管理器中更新到最新的 SDK 解决了这次崩溃。我仍然没有收到任何推送通知,但我猜这是由于其他问题造成的。至少应用程序在尝试注册推送通知时不会再崩溃。
来自 Intercom 的 Dale。您是否使用任何其他第三方推送提供商,或者您是否有自己的 GCM 接收器?他们有可能正在消耗我们的推动力而不是传递它们。这在 Xamarin、Phonegap、Cordova 等中可能很困难。通常注册和接收服务不可用。我在下面包含了我们的 GCM 文档和可能与您最相关的部分的 link。如果这不能帮助解决问题,请通过 cordova 存储库与我们联系:https://github.com/intercom/intercom-cordova 或在您的 Intercom 仪表板中联系我们/发送电子邮件至 team@intercom.io。
可能导致您设置困难的问题是:
第 7 步。将 Intercom 与其他 GCM 设置一起使用(可选)
这仅适用于为自己的内容也使用 GCM 或为 GCM 使用第三方服务的应用程序。您需要更新 GcmListenerService 和生成设备令牌的 class。
您应该有一个 class 来生成推送设备令牌并将其发送到您的后端。除了将令牌发送到您的后端之外,您还需要将其转发到 Intercom,如下所示:
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 的 class。该服务将消耗用于 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
}
}