Skip to content

Commit 26c6e14

Browse files
Add unregister functionality.
1 parent 835f6a0 commit 26c6e14

File tree

6 files changed

+40
-1
lines changed

6 files changed

+40
-1
lines changed

sdk/Notifo.SDK/NotifoMobilePush/INotifoMobilePush.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,10 @@ public partial interface INotifoMobilePush : INotifoClient
5656
/// Register for notifications on demand.
5757
/// </summary>
5858
void Register();
59+
60+
/// <summary>
61+
/// Unregister notifications on demand.
62+
/// </summary>
63+
void Unregister();
5964
}
6065
}

sdk/Notifo.SDK/NotifoMobilePush/NotifoMobilePushImplementation.shared.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,24 @@ public void Register()
173173
}
174174
}
175175

176+
public void Unregister()
177+
{
178+
try
179+
{
180+
string token = settings.Token;
181+
if (!string.IsNullOrWhiteSpace(token))
182+
{
183+
_ = MobilePush.DeleteTokenAsync(token);
184+
}
185+
186+
settings.Clear();
187+
}
188+
catch (Exception ex)
189+
{
190+
Log.Error(ex, Strings.TokenRemoveFailException);
191+
}
192+
}
193+
176194
private void PushEventsProvider_OnNotificationReceived(object sender, NotificationEventArgs e)
177195
{
178196
// we are tracking notifications only for Android here because it is the entry point for all notifications that the Android device receives

sdk/Notifo.SDK/Resources/Strings.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/Notifo.SDK/Resources/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
<data name="TokenRefreshSuccess" xml:space="preserve">
157157
<value>Token was successfully refreshed. Token: {0}</value>
158158
</data>
159+
<data name="TokenRemoveFailException" xml:space="preserve">
160+
<value>Fail to remove push token on the server.</value>
161+
</data>
159162
<data name="TrackingException" xml:space="preserve">
160163
<value>Fail to track notification.</value>
161164
</data>

sdk/Notifo.SDK/Services/ISettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ internal interface ISettings
2323
Task TrackNotificationsAsync(IEnumerable<Guid> ids);
2424

2525
SlidingSet<Guid> GetSeenNotifications();
26+
27+
void Clear();
2628
}
2729
}

sdk/Notifo.SDK/Services/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,7 @@ public async Task TrackNotificationsAsync(IEnumerable<Guid> ids)
7676
Semaphore.Release();
7777
}
7878
}
79+
80+
public void Clear() => Preferences.Clear(SharedName);
7981
}
8082
}

0 commit comments

Comments
 (0)