I'm developing xamarin forms application for both android and iOS. I'm implementing the PushNotifications for the same using Parse SDK. I've added Parse.Android dll in references of .Droid project and Parse.iOS dll in references of .iOS project. My problem is sometimes on Android I'm not able to retrieve the DeviceToken. There're no entries for DeviceToken and pushtype in the parse installation class. It's values are 'undefined'. Below is my code along with manifest.
public async void RegisterForPushNotifications ()
{
try {
if (Utility.isNetworkConnected ()) {
await ParsePush.SubscribeAsync ("");
var installation = ParseInstallation.CurrentInstallation;
// I'm saving the DeviceToken in App.regId for future uses
App.regId = System.String.IsNullOrWhiteSpace (installation.DeviceToken) ? "" : installation.DeviceToken;
ParsePush.ParsePushNotificationReceived += PushNotificationReceived;
}
} catch (ParseException e) {
System.Diagnostics.Debug.WriteLine (e.StackTrace);
} catch (Java.Lang.Exception e) {
e.PrintStackTrace ();
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.nirvaniclabs">
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23" />
<application android:label="RxLifetime" android:icon="@drawable/icon" android:largeHeap="true">
<receiver android:name="parse.ParsePushBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.nirvaniclabs" />
</intent-filter>
</receiver>
<service android:name="parse.ParsePushService" />
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.LOCATION_HARDWARE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature" android:name="com.nirvaniclabs.permission.C2D_MESSAGE" />
<uses-permission android:name="com.nirvaniclabs.permission.C2D_MESSAGE" />
</manifest>
Also some times above mentioned code is causing crashes at app startup. I've reported this issue here and here
Also ParseClient.Initialize
is the very first line of 'OnCreate' method of MainActivity where I'm passing parse keys required for initialization.
I'm calling RegisterForPushNotifications method after LoadApplication (new App ())
is called.
Attached below is the screenshot of parse installation class.
Please let me know if there's some issue in my code or is it the issue with parse SDK.