Exemplo n.º 1
0
        public async Task RegisterAccountWithSdkAsync()
        {
            if (RegistrationState != AccountRegistrationState.InAppCacheAndSdkCache)
            {
                throw new Exception("Account must be in both SDK and App cache before it can be registered");
            }

            var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

            ConnectedDevicesNotificationRegistration registration = new ConnectedDevicesNotificationRegistration();

            registration.Type  = ConnectedDevicesNotificationType.WNS;
            registration.Token = channel.Uri;
            var account        = new ConnectedDevicesAccount(Id, Type);
            var registerResult = await m_platform.NotificationRegistrationManager.RegisterAsync(account, registration);

            // It would be a good idea for apps to take a look at the different statuses here and perhaps attempt some sort of remediation.
            // For example, web failure may indicate that a web service was temporarily in a bad state and retries may be successful.
            //
            // NOTE: this approach was chosen rather than using exceptions to help separate "expected" / "retry-able" errors from real
            // exceptions and keep the error-channel logic clean and simple.
            if (registerResult.Status == ConnectedDevicesNotificationRegistrationStatus.Success)
            {
                await UserNotifications.RegisterAccountWithSdkAsync();
            }
        }
Exemplo n.º 2
0
        public async Task RegisterAccountWithSdkAsync()
        {
            if (RegistrationState != AccountRegistrationState.InAppCacheAndSdkCache)
            {
                throw new Exception("Account must be in both SDK and App cache before it can be registered");
            }

            var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

            ConnectedDevicesNotificationRegistration registration = new ConnectedDevicesNotificationRegistration();

            registration.Type  = ConnectedDevicesNotificationType.WNS;
            registration.Token = channel.Uri;
            var account = new ConnectedDevicesAccount(Id, Type);
            await m_platform.NotificationRegistrationManager.RegisterForAccountAsync(account, registration);

            await UserNotifications.RegisterAccountWithSdkAsync();
        }