private async Task<PushConfiguration> CreatePushConfiguration(RemoteChannelDetails remoteChannelDetails = null) { var details = remoteChannelDetails ?? await _registrationContext.GetRemoteChannelDetails(); if (details == null) { return null; } switch (_environmentInformation.OperatingSystem) { case "Android": return new GcmPushConfiguration { RegistrationId = details.Token }; case "iOS": var apns = new ApnsPushConfiguration { BundleId = this._environmentInformation.AppIdentifier, Token = details.Token, MessageAlertSound = NotificationSoundFilename }; return apns; default: throw new NotSupportedException( "Invalid operating system {0}".FormatUsing(_environmentInformation.OperatingSystem)); } }
public async Task SetRemoteChannelDetails(RemoteChannelDetails details) { _remoteChannelDetails = details; await SetValueAsync(details, "RemoteChannelDetails"); }
public async Task UpdatePushRegistrationAsync(RemoteChannelDetails details) { if (details == null) { return; } try { await _synchroniseLock.WaitAsync(); var existingDetails = await _registrationContext.GetRemoteChannelDetails(); if (existingDetails == null || existingDetails.Token != details.Token) { if (!string.IsNullOrEmpty(details.Token)) { await _secureRegistrationService.UpdatePushRegistrationAsync(await CreatePushConfiguration(details)); await _registrationContext.SetRemoteChannelDetails(details); } } } finally { _synchroniseLock.Release(); } }
public async Task<RemoteChannelDetails> GetRemoteChannelDetails() { return _remoteChannelDetails ?? (_remoteChannelDetails = await GetValueAsync<RemoteChannelDetails>("RemoteChannelDetails")); }