|
13 | 13 | using Plugin.FirebasePushNotification;
|
14 | 14 | using UserNotifications;
|
15 | 15 |
|
16 |
| -namespace Notifo.SDK.FirebasePlugin |
| 16 | +namespace Notifo.SDK.FirebasePlugin; |
| 17 | + |
| 18 | +/// <summary> |
| 19 | +/// Plugin initialization. |
| 20 | +/// </summary> |
| 21 | +public class NotifoFirebasePlugin |
17 | 22 | {
|
18 | 23 | /// <summary>
|
19 |
| - /// Plugin initialization. |
| 24 | + /// Initializes the firebase plugin. |
20 | 25 | /// </summary>
|
21 |
| - public class NotifoFirebasePlugin |
| 26 | + /// <param name="options">Application launch options.</param> |
| 27 | + /// <param name="notifoStartup">The <see cref="INotifoStartup"/> implementation.</param> |
| 28 | + /// <param name="notificationHandler">The <see cref="INotificationHandler"/> implementation.</param> |
| 29 | + /// <param name="autoRegistration">Automatically register for push notifications.</param> |
| 30 | + public static void Initialize(NSDictionary options, INotifoStartup notifoStartup, INotificationHandler notificationHandler = null, bool autoRegistration = true) |
22 | 31 | {
|
23 |
| - /// <summary> |
24 |
| - /// Initializes the firebase plugin. |
25 |
| - /// </summary> |
26 |
| - /// <param name="options">Application launch options.</param> |
27 |
| - /// <param name="notifoStartup">The <see cref="INotifoStartup"/> implementation.</param> |
28 |
| - /// <param name="notificationHandler">The <see cref="INotificationHandler"/> implementation.</param> |
29 |
| - /// <param name="autoRegistration">Automatically register for push notifications.</param> |
30 |
| - public static void Initialize(NSDictionary options, INotifoStartup notifoStartup, INotificationHandler notificationHandler = null, bool autoRegistration = true) |
31 |
| - { |
32 |
| - FirebasePushNotificationManager.Initialize(options, autoRegistration); |
| 32 | + FirebasePushNotificationManager.Initialize(options, autoRegistration); |
33 | 33 |
|
34 |
| - NotifoIO.Current.SetNotificationHandler(notificationHandler); |
35 |
| - notifoStartup.ConfigureService(NotifoIO.Current); |
36 |
| - } |
| 34 | + NotifoIO.Current.SetNotificationHandler(notificationHandler); |
| 35 | + notifoStartup.ConfigureService(NotifoIO.Current); |
| 36 | + } |
| 37 | + |
| 38 | + /// <summary> |
| 39 | + /// Invoked when the application received a remote notification. |
| 40 | + /// </summary> |
| 41 | + /// <param name="data">The notification data dictionary.</param> |
| 42 | + /// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns> |
| 43 | + public static async Task DidReceiveMessageAsync(NSDictionary data) |
| 44 | + { |
| 45 | + NotifoIO.Current.RaiseDebug(Strings.ReceivedNotification, null, data); |
37 | 46 |
|
38 |
| - /// <summary> |
39 |
| - /// Invoked when the application received a remote notification. |
40 |
| - /// </summary> |
41 |
| - /// <param name="data">The notification data dictionary.</param> |
42 |
| - /// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns> |
43 |
| - public static async Task DidReceiveMessageAsync(NSDictionary data) |
| 47 | + if (ContainsPullRefreshRequest(data)) |
44 | 48 | {
|
45 |
| - NotifoIO.Current.RaiseDebug(Strings.ReceivedNotification, null, data); |
| 49 | + await NotifoIO.DidReceivePullRefreshRequestAsync(); |
| 50 | + } |
46 | 51 |
|
47 |
| - if (ContainsPullRefreshRequest(data)) |
48 |
| - { |
49 |
| - await NotifoIO.DidReceivePullRefreshRequestAsync(); |
50 |
| - } |
| 52 | + FirebasePushNotificationManager.DidReceiveMessage(data); |
| 53 | + } |
51 | 54 |
|
52 |
| - FirebasePushNotificationManager.DidReceiveMessage(data); |
53 |
| - } |
| 55 | + /// <summary> |
| 56 | + /// Indicates that a call to <see cref="UIKit.UIApplication.RegisterForRemoteNotifications"/> succeeded. |
| 57 | + /// </summary> |
| 58 | + /// <param name="deviceToken">The device token.</param> |
| 59 | + public static void DidRegisterRemoteNotifications(NSData deviceToken) |
| 60 | + { |
| 61 | + FirebasePushNotificationManager.DidRegisterRemoteNotifications(deviceToken); |
| 62 | + } |
54 | 63 |
|
55 |
| - /// <summary> |
56 |
| - /// Indicates that a call to <see cref="UIKit.UIApplication.RegisterForRemoteNotifications"/> succeeded. |
57 |
| - /// </summary> |
58 |
| - /// <param name="deviceToken">The device token.</param> |
59 |
| - public static void DidRegisterRemoteNotifications(NSData deviceToken) |
60 |
| - { |
61 |
| - FirebasePushNotificationManager.DidRegisterRemoteNotifications(deviceToken); |
62 |
| - } |
| 64 | + /// <summary> |
| 65 | + /// Indicates that a call to <see cref="UIKit.UIApplication.RegisterForRemoteNotifications"/> failed. |
| 66 | + /// </summary> |
| 67 | + /// <param name="error">The error.</param> |
| 68 | + public static void RemoteNotificationRegistrationFailed(NSError error) |
| 69 | + { |
| 70 | + FirebasePushNotificationManager.RemoteNotificationRegistrationFailed(error); |
| 71 | + } |
63 | 72 |
|
64 |
| - /// <summary> |
65 |
| - /// Indicates that a call to <see cref="UIKit.UIApplication.RegisterForRemoteNotifications"/> failed. |
66 |
| - /// </summary> |
67 |
| - /// <param name="error">The error.</param> |
68 |
| - public static void RemoteNotificationRegistrationFailed(NSError error) |
69 |
| - { |
70 |
| - FirebasePushNotificationManager.RemoteNotificationRegistrationFailed(error); |
71 |
| - } |
| 73 | + /// <summary> |
| 74 | + /// Method for processing the user's response to a delivered notification. |
| 75 | + /// </summary> |
| 76 | + /// <param name="center">The shared user notification center object that received the notification.</param> |
| 77 | + /// <param name="response">The user's response to the notification.</param> |
| 78 | + /// <param name="completionHandler">The action to execute when you have finished processing the user's response.</param> |
| 79 | + public static void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) |
| 80 | + { |
| 81 | + NotifoIO.DidReceiveNotificationResponse(center, response, completionHandler); |
72 | 82 |
|
73 |
| - /// <summary> |
74 |
| - /// Method for processing the user's response to a delivered notification. |
75 |
| - /// </summary> |
76 |
| - /// <param name="center">The shared user notification center object that received the notification.</param> |
77 |
| - /// <param name="response">The user's response to the notification.</param> |
78 |
| - /// <param name="completionHandler">The action to execute when you have finished processing the user's response.</param> |
79 |
| - public static void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) |
| 83 | + if (CrossFirebasePushNotification.Current is IUNUserNotificationCenterDelegate notificationDelegate) |
80 | 84 | {
|
81 |
| - NotifoIO.DidReceiveNotificationResponse(center, response, completionHandler); |
82 |
| - |
83 |
| - if (CrossFirebasePushNotification.Current is IUNUserNotificationCenterDelegate notificationDelegate) |
84 |
| - { |
85 |
| - notificationDelegate.DidReceiveNotificationResponse(center, response, completionHandler); |
86 |
| - } |
| 85 | + notificationDelegate.DidReceiveNotificationResponse(center, response, completionHandler); |
87 | 86 | }
|
| 87 | + } |
88 | 88 |
|
89 |
| - private static bool ContainsPullRefreshRequest(NSDictionary data) |
90 |
| - { |
91 |
| - var aps = data?.ObjectForKey(new NSString(Constants.ApsKey)) as NSDictionary; |
| 89 | + private static bool ContainsPullRefreshRequest(NSDictionary data) |
| 90 | + { |
| 91 | + var aps = data?.ObjectForKey(new NSString(Constants.ApsKey)) as NSDictionary; |
92 | 92 |
|
93 |
| - return aps != null && aps.ContainsKey(new NSString(Constants.ContentAvailableKey)); |
94 |
| - } |
| 93 | + return aps != null && aps.ContainsKey(new NSString(Constants.ContentAvailableKey)); |
95 | 94 | }
|
96 | 95 | }
|
0 commit comments