@@ -17,24 +17,36 @@ internal partial class NotifoMobilePushImplementation : NSObject
17
17
{
18
18
private INotificationHandler ? notificationHandler ;
19
19
20
+ /// <inheritdoc />
20
21
public INotifoMobilePush SetNotificationHandler ( INotificationHandler ? notificationHandler )
21
22
{
22
23
this . notificationHandler = notificationHandler ;
23
24
return this ;
24
25
}
25
26
26
- public async Task DidReceiveNotificationRequestAsync ( UNNotificationRequest request , UNMutableNotificationContent bestAttemptContent )
27
+ /// <inheritdoc />
28
+ public async Task DidReceiveNotificationRequestAsync ( UNNotificationRequest request , UNMutableNotificationContent content )
27
29
{
28
30
RaiseDebug ( Strings . ReceivedNotification , this , request . Content . UserInfo ) ;
29
31
30
32
var notification = new UserNotificationDto ( ) . FromDictionary ( request . Content . UserInfo . ToDictionary ( ) ) ;
31
33
32
- await EnrichNotificationContentAsync ( bestAttemptContent , notification ) ;
34
+ // We have ony limited time in the notification service, so we dot things in the right order.
33
35
34
- // Always track our notifications as seen.
36
+ // 1. Do the cheap enrichment first.
37
+ await EnrichBasicAsync ( content , notification ) ;
38
+
39
+ // 2. Do the tracking to ensure that the request arrives.
35
40
await TrackNotificationsAsync ( notification ) ;
41
+
42
+ // 3. Enrich with images, which need to be downloaded.
43
+ await EnrichImagesAsync ( content , notification ) ;
44
+
45
+ // 4. Custom enrichment code (could be potentially be expensive).
46
+ EnrichWithCustomCode ( content , notification ) ;
36
47
}
37
48
49
+ /// <inheritdoc />
38
50
public async Task DidReceivePullRefreshRequestAsync ( PullRefreshOptions ? options = null )
39
51
{
40
52
options ??= new PullRefreshOptions ( ) ;
@@ -131,10 +143,15 @@ private void OnReceived(NotificationEventArgs eventArgs)
131
143
132
144
private async Task ShowLocalNotificationAsync ( UserNotificationDto notification )
133
145
{
134
- var content = new UNMutableNotificationContent ( ) ;
146
+ var content = new UNMutableNotificationContent
147
+ {
148
+ UserInfo = notification . ToDictionary ( ) . ToNSDictionary ( )
149
+ } ;
150
+
151
+ await EnrichBasicAsync ( content , notification ) ;
152
+ await EnrichImagesAsync ( content , notification ) ;
135
153
136
- content = await EnrichNotificationContentAsync ( content , notification ) ;
137
- content . UserInfo = notification . ToDictionary ( ) . ToNSDictionary ( ) ;
154
+ EnrichWithCustomCode ( content , notification ) ;
138
155
139
156
var request = UNNotificationRequest . FromIdentifier ( notification . Id . ToString ( ) , content , trigger : null ) ;
140
157
@@ -147,7 +164,7 @@ private async Task ShowLocalNotificationAsync(UserNotificationDto notification)
147
164
} ) ;
148
165
}
149
166
150
- private async Task < UNMutableNotificationContent > EnrichNotificationContentAsync ( UNMutableNotificationContent content , UserNotificationDto notification )
167
+ private async Task EnrichBasicAsync ( UNMutableNotificationContent content , UserNotificationDto notification )
151
168
{
152
169
if ( ! string . IsNullOrWhiteSpace ( notification . Subject ) )
153
170
{
@@ -159,8 +176,6 @@ private async Task<UNMutableNotificationContent> EnrichNotificationContentAsync(
159
176
content . Body = notification . Body ;
160
177
}
161
178
162
- await AddImageAsync ( content , notification ) ;
163
-
164
179
var actions = new List < UNNotificationAction > ( ) ;
165
180
166
181
if ( ! string . IsNullOrWhiteSpace ( notification . ConfirmUrl ) &&
@@ -226,12 +241,15 @@ private async Task<UNMutableNotificationContent> EnrichNotificationContentAsync(
226
241
227
242
content . Sound ??= UNNotificationSound . Default ;
228
243
229
- notificationHandler ? . OnBuildNotification ( content , notification ) ;
244
+ EnrichWithCustomCode ( content , notification ) ;
245
+ }
230
246
231
- return content ;
247
+ private void EnrichWithCustomCode ( UNMutableNotificationContent content , UserNotificationDto notification )
248
+ {
249
+ notificationHandler ? . OnBuildNotification ( content , notification ) ;
232
250
}
233
251
234
- private async Task AddImageAsync ( UNMutableNotificationContent content , UserNotificationDto notification )
252
+ private async Task EnrichImagesAsync ( UNMutableNotificationContent content , UserNotificationDto notification )
235
253
{
236
254
var image = string . IsNullOrWhiteSpace ( notification . ImageLarge ) ? notification . ImageSmall : notification . ImageLarge ;
237
255
0 commit comments