Пример #1
0
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            // Get current device token
            var DeviceToken = deviceToken.Description;

            if (!string.IsNullOrWhiteSpace(DeviceToken))
            {
                DeviceToken = DeviceToken.Trim('<').Trim('>').Replace(" ", "");
            }

            Console.WriteLine(" PushDeviceToken ###" + DeviceToken.Replace(' ', ' '));

            // Get previous device token
            var oldDeviceToken = NSUserDefaults.StandardUserDefaults.StringForKey("PushDeviceToken");

            // Has the token changed?
            if (string.IsNullOrEmpty(oldDeviceToken) || !oldDeviceToken.Equals(DeviceToken))
            {
                ALRegisterUserClientService registerUserClientService = new ALRegisterUserClientService();

                registerUserClientService.UpdateApnDeviceTokenWithCompletion(DeviceToken, (rResponse, error) =>
                {
                    if (error != null)
                    {
                        Console.WriteLine("REGISTRATION ERROR :: {0}", error.Description);
                        return;
                    }
                    Console.WriteLine("Registration response from server : {0}", rResponse);
                });
            }

            // Save new device token
            NSUserDefaults.StandardUserDefaults.SetString(DeviceToken, "PushDeviceToken");
        }
Пример #2
0
        partial void LoginButton_TouchUpInside(UIButton sender)
        {
            //Registration code here. Build your user details.
            ALUser user = new ALUser();

            user.ApplicationId = ALChatManager.application_id;
            user.UserId        = userIdTextField.Text;
            user.Password      = passwordTextField.Text;
            ALUserDefaultsHandler.SetPassword(user.Password);
            ALUserDefaultsHandler.SetUserAuthenticationTypeId((short)AuthenticationType.Applozic);

            //Applozic registartion code.
            ALRegisterUserClientService userClientService = new ALRegisterUserClientService();

            userClientService.InitWithCompletion(user, (ALRegistrationResponse response, NSError error) =>
            {
                if (error == null && response.DeviceKey != null)
                {
                    //Check for APNS deviceToken. If not done already, ask for registartion token.
                    if (String.IsNullOrEmpty(ALUserDefaultsHandler.ApnDeviceToken))
                    {
                        ALChatManager.registerNotification();
                    }

                    UIStoryboard Storyboard = UIStoryboard.FromName("Main", null);
                    MainViewController MainViewController = Storyboard.InstantiateViewController("MainViewController") as MainViewController;
                    this.PresentViewController(MainViewController, true, () => { });
                }
                else
                {
                    String description = error != null ? error.LocalizedDescription : response.Message;
                    new UIAlertView("Opps!!!", description, null, "OK", null).Show();
                }
            });
        }