/// <summary> /// Unsubcribe Multiple Tokens /// </summary> /// <param name="RegistrationToken"></param> /// <param name="Topic"></param> public async void UnSubscribeFromTopic(string[] RegistrationToken, string Topic) { if (string.IsNullOrEmpty(Configuration.FCM_SERVER_KEY)) { mListener.OnError(new Exception("Server Key should not be empty")); } if (RegistrationToken.Length > 0) { mListener.OnError(new Exception("Should use this for multiple registration tokens")); } if (string.IsNullOrEmpty(Topic)) { mListener.OnError(new Exception("Topic should not be empty")); } this.RegistrationToken = RegistrationToken; this.Topic = Topic; string Subscription = await TopicClient(Configuration.BATCH_REMOVE); FcmResponse fcmResponse = DeSerializeContent(typeof(FcmResponse), Subscription) as FcmResponse; if (fcmResponse.results.Length > 0 && !string.IsNullOrEmpty(fcmResponse.results[0].error)) { if (mListener != null) { string[] errors = fcmResponse.results.Where(x => x.error != null).Select(x => x.error).ToArray(); List <string> RegTokens = new List <string>(); for (int i = 0; i < RegistrationToken.Length; i++) { if (fcmResponse.results[i].error != null) { RegTokens.Add(RegistrationToken[i]); } } string[] RegistrationTokens = RegTokens.ToArray(); mListener.OnSuccess(RegistrationTokens, errors); } } else { if (mListener != null) { mListener.OnSuccess(); } } }
/// <summary> /// Subscribe a Single Token /// </summary> /// <param name="RegistrationToken"></param> /// <param name="Topic"></param> public async void SubscribeToTopic(string RegistrationToken, string Topic) { if (string.IsNullOrEmpty(Configuration.FCM_SERVER_KEY)) { sListener.OnError(new Exception("Server Key should not be empty")); } if (string.IsNullOrEmpty(RegistrationToken)) { sListener.OnError(new Exception("Registration Token should not be empty")); } if (string.IsNullOrEmpty(Topic)) { sListener.OnError(new Exception("Topic should not be empty")); } this.RegistrationToken = new string[] { RegistrationToken }; this.Topic = Topic; string Subscription = await TopicClient(Configuration.BATCH_ADD); FcmResponse fcmResponse = DeSerializeContent(typeof(FcmResponse), Subscription) as FcmResponse; if (fcmResponse.results.Length > 0 && !string.IsNullOrEmpty(fcmResponse.results[0].error)) { if (sListener != null) { sListener.OnSuccess(RegistrationToken, fcmResponse.results[0].error); } } else { if (sListener != null) { sListener.OnSuccess(); } } }