/// <summary> /// Initializes the Parse SDK and begins running network requests created by Parse. /// </summary> public virtual void Awake() { Initialize(); // Force the name to be `ParseInitializeBehaviour` in runtime. gameObject.name = "ParseInitializeBehaviour"; if (PlatformHooks.IsIOS) { PlatformHooks.RegisterDeviceTokenRequest((deviceToken) => { if (deviceToken != null) { ParseInstallation installation = ParseInstallation.CurrentInstallation; installation.SetDeviceTokenFromData(deviceToken); // Optimistically assume this will finish. installation.SaveAsync(); } }); } }
/// <summary> /// Handles GCM registration intent from <see cref="ParsePushBroadcastReceiver"/> and saves the GCM registration /// id as <see cref="ParseInstallation.CurrentInstallation"/> device token. /// </summary> /// <remarks> /// Should be called by a broadcast receiver or service to handle GCM registration response /// intent (com.google.android.c2dm.intent.REGISTRATION). /// </remarks> /// <param name="intent"></param> public Task HandleRegistrationIntentAsync(Intent intent) { if (intent.Action == ParsePushBroadcastReceiver.ActionGcmRegisterResponse) { string registrationId = intent.GetStringExtra(ExtraRegistrationId); if (registrationId != null && registrationId.Length > 0) { Android.Util.Log.Info(LogTag, "GCM registration successful. Registration Id: " + registrationId); ParseInstallation installation = ParseInstallation.CurrentInstallation; // Set `pushType` via internal `Set` method since we want to skip mutability check. installation.Set("pushType", "gcm"); installation.DeviceToken = registrationId; return(installation.SaveAsync()); } } return(Task.FromResult(0)); }