0

本周,我通过一对夫妻绑定库向我们的Xamarin.Forms应用程序添加了IntercomIO SDK,目前我试图让推送通知工作,但不久后我在MainActivity中调用PushHandlerService.Register(this)时,应用程序崩溃,说它无法找到com.google.android.gms.gcm.GcmReceiver类,该类甚至没有被围绕此调用的try catch块捕获。无法注册Xamarin Android上的推送通知以及IntercomIO

以下是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(本)的问题不会发生,但是那显然我不能再次收到推送通知(包括我们自己系统的推送通知)

这是怎么回事?我已经正确设置了库和依赖项,但似乎无法找到GcmReceiver类。

回答

1

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

0

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

我们拥有GCM文档浏览:https://docs.intercom.com/configure-intercom-for-your-product-or-site/configure-intercom-for-mobile/enable-push-notifications-with-intercom-for-android-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,像这样:

我能取得今天的工作,我们的GCM建立不合作出于某种原因,并创建一个新的后(基于FCM
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 
    } 
} 
+0

)它开始按预期工作。 – zezioen