Appverse.Core.PushNotifications.AbstractPushNotifications.RegisteredForRemoteNotifications C# (CSharp) Method

RegisteredForRemoteNotifications() public method

public RegisteredForRemoteNotifications ( UIApplication application, NSData deviceToken ) : void
application UIApplication
deviceToken NSData
return void
		public override void RegisteredForRemoteNotifications (UIApplication application, NSData deviceToken)
		{
			// The deviceToken is what the push notification server needs to send out a notification
			// to the device. Most times application needs to send the device Token to its servers when it has changed

			SystemLogger.Log (SystemLogger.Module.PLATFORM, "Success registering for Remote Notifications");

			// ****** REMOVED "lastDeviceToken storage" feature. Marga 06/08/2013 . Platform will always call the JS listener; same behavior in all platforms ******

			// First, get the last device token we know of
			// string lastDeviceToken = NSUserDefaults.StandardUserDefaults.StringForKey("deviceToken");

			//There's probably a better way to do this
			//NSString strFormat = new NSString("%@");
			//NSString newToken = new NSString(ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr(new ObjCRuntime.Class("NSString").Handle, new ObjCRuntime.Selector("stringWithFormat:").Handle, strFormat.Handle, deviceToken.Handle));

			NSString newToken = new NSString (deviceToken.ToString ());

			var newDeviceToken = newToken.ToString().Replace("<", "").Replace(">", "").Replace(" ", "");
			SystemLogger.Log (SystemLogger.Module.PLATFORM, "Device token: " + newDeviceToken);

			// We only want to send the device token to the server if it hasn't changed since last time
			// no need to incur extra bandwidth by sending the device token every time
			// if (!newDeviceToken.Equals(lastDeviceToken))
			//{
			// Send the new device token to your application server
			// ****** REMOVED "lastDeviceToken storage" feature. Marga 06/08/2013 . Platform will always call the JS listener; same behavior in all platforms ******

			RegistrationToken registrationToken = new RegistrationToken();
			registrationToken.StringRepresentation = newDeviceToken;
			byte[] buffer = new byte[deviceToken.Length];
			Marshal.Copy(deviceToken.Bytes, buffer,0,buffer.Length);
			registrationToken.Binary = buffer;
			PushNotificationsUtils.FireUnityJavascriptEvent("Appverse.PushNotifications.OnRegisterForRemoteNotificationsSuccess", registrationToken);

			//Save the new device token for next application launch
			// NSUserDefaults.StandardUserDefaults.SetString(newDeviceToken, "deviceToken");
		}