|
| 1 | +/* |
| 2 | + * Copyright 2024 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +namespace Firebase.Messaging { |
| 18 | + |
| 19 | +/// @brief Firebase Cloud Messaging API. |
| 20 | +/// |
| 21 | +/// Firebase Cloud Messaging allows you to send data from your server to your |
| 22 | +/// users' devices, and receive messages from devices on the same connection |
| 23 | +/// if you're using a XMPP server. |
| 24 | +/// |
| 25 | +/// The FCM service handles all aspects of queueing of messages and delivery |
| 26 | +/// to client applications running on target devices. |
| 27 | +public static class FirebaseMessaging { |
| 28 | + |
| 29 | + /// Enable or disable token registration during initialization of Firebase |
| 30 | + /// Cloud Messaging. |
| 31 | + /// |
| 32 | + /// This token is what identifies the user to Firebase, so disabling this |
| 33 | + /// avoids creating any new identity and automatically sending it to Firebase, |
| 34 | + /// unless consent has been granted. |
| 35 | + /// |
| 36 | + /// If this setting is enabled, it triggers the token registration refresh |
| 37 | + /// immediately. This setting is persisted across app restarts and overrides |
| 38 | + /// the setting "firebase_messaging_auto_init_enabled" specified in your |
| 39 | + /// Android manifest (on Android) or Info.plist (on iOS and tvOS). |
| 40 | + /// |
| 41 | + /// <p>By default, token registration during initialization is enabled. |
| 42 | + /// |
| 43 | + /// The registration happens before you can programmatically disable it, so |
| 44 | + /// if you need to change the default, (for example, because you want to |
| 45 | + /// prompt the user before FCM generates/refreshes a registration token on app |
| 46 | + /// startup), add to your application’s manifest: |
| 47 | + /// |
| 48 | + /// @if NOT_DOXYGEN |
| 49 | + /// <meta-data android:name="firebase_messaging_auto_init_enabled" |
| 50 | + /// android:value="false" /> |
| 51 | + /// @else |
| 52 | + /// @code |
| 53 | + /// <meta-data android:name="firebase_messaging_auto_init_enabled" |
| 54 | + /// android:value="false" /> |
| 55 | + /// @endcode |
| 56 | + /// @endif |
| 57 | + /// |
| 58 | + /// or on iOS or tvOS to your Info.plist: |
| 59 | + /// |
| 60 | + /// @if NOT_DOXYGEN |
| 61 | + /// <key>FirebaseMessagingAutoInitEnabled</key> |
| 62 | + /// <false/> |
| 63 | + /// @else |
| 64 | + /// @code |
| 65 | + /// <key>FirebaseMessagingAutoInitEnabled</key> |
| 66 | + /// <false/> |
| 67 | + /// @endcode |
| 68 | + /// @endif |
| 69 | + public static bool TokenRegistrationOnInitEnabled { |
| 70 | + get { |
| 71 | + return FirebaseMessagingInternal.IsTokenRegistrationOnInitEnabled(); |
| 72 | + } |
| 73 | + set { |
| 74 | + FirebaseMessagingInternal.SetTokenRegistrationOnInitEnabled(value); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + /// Enables or disables Firebase Cloud Messaging message delivery metrics |
| 79 | + /// export to BigQuery. |
| 80 | + /// |
| 81 | + /// By default, message delivery metrics are not exported to BigQuery. Use |
| 82 | + /// this method to enable or disable the export at runtime. In addition, you |
| 83 | + /// can enable the export by adding to your manifest. Note that the run-time |
| 84 | + /// method call will override the manifest value. |
| 85 | + /// |
| 86 | + /// @code |
| 87 | + /// <meta-data android:name= "delivery_metrics_exported_to_big_query_enabled" |
| 88 | + /// android:value="true"/> |
| 89 | + /// @endcode |
| 90 | + /// |
| 91 | + /// @note This function is currently only implemented on Android, and has no |
| 92 | + /// behavior on other platforms. |
| 93 | + public static bool DeliveryMetricsExportedToBigQueryEnabled { |
| 94 | + get { |
| 95 | + return FirebaseMessagingInternal.DeliveryMetricsExportToBigQueryEnabled(); |
| 96 | + } |
| 97 | + set { |
| 98 | + FirebaseMessagingInternal.SetDeliveryMetricsExportToBigQuery(value); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + /// @brief This creates a Firebase Installations ID, if one does not exist, and |
| 103 | + /// sends information about the application and the device where it's running to |
| 104 | + /// the Firebase backend. |
| 105 | + /// |
| 106 | + /// @return A task with the token. |
| 107 | + public static System.Threading.Tasks.Task<string> GetTokenAsync() { |
| 108 | + return FirebaseMessagingInternal.GetTokenAsync(); |
| 109 | + } |
| 110 | + |
| 111 | + /// @brief Deletes the default token for this Firebase project. |
| 112 | + /// |
| 113 | + /// Note that this does not delete the Firebase Installations ID that may have |
| 114 | + /// been created when generating the token. See Installations.Delete() for |
| 115 | + /// deleting that. |
| 116 | + /// |
| 117 | + /// @return A task that completes when the token is deleted. |
| 118 | + public static System.Threading.Tasks.Task DeleteTokenAsync() { |
| 119 | + return FirebaseMessagingInternal.DeleteTokenAsync(); |
| 120 | + } |
| 121 | + |
| 122 | +#if DOXYGEN |
| 123 | + /// Called on the client when a message arrives. |
| 124 | + public static event System.EventHandler<MessageReceivedEventArgs> MessageReceived; |
| 125 | +#else |
| 126 | + public static event System.EventHandler<MessageReceivedEventArgs> MessageReceived { |
| 127 | + add { |
| 128 | + FirebaseMessagingInternal.MessageReceived += value; |
| 129 | + } |
| 130 | + remove { |
| 131 | + FirebaseMessagingInternal.MessageReceived -= value; |
| 132 | + } |
| 133 | + } |
| 134 | +#endif // DOXYGEN |
| 135 | + |
| 136 | +#if DOXYGEN |
| 137 | + /// Called on the client when a registration token message arrives. |
| 138 | + public static event System.EventHandler<TokenReceivedEventArgs> TokenReceived; |
| 139 | +#else |
| 140 | + public static event System.EventHandler<TokenReceivedEventArgs> TokenReceived { |
| 141 | + add { |
| 142 | + FirebaseMessagingInternal.TokenReceived += value; |
| 143 | + } |
| 144 | + remove { |
| 145 | + FirebaseMessagingInternal.TokenReceived -= value; |
| 146 | + } |
| 147 | + } |
| 148 | +#endif |
| 149 | + |
| 150 | + /// @brief Displays a prompt to the user requesting permission to display |
| 151 | + /// notifications. |
| 152 | + /// |
| 153 | + /// The permission prompt only appears on iOS and tvOS. If the user has |
| 154 | + /// already agreed to allow notifications, no prompt is displayed and the |
| 155 | + /// returned future is completed immediately. |
| 156 | + /// |
| 157 | + /// @return A Task that completes when the notification prompt has been |
| 158 | + /// dismissed. |
| 159 | + public static System.Threading.Tasks.Task RequestPermissionAsync() { |
| 160 | + return FirebaseMessagingInternal.RequestPermissionAsync(); |
| 161 | + } |
| 162 | + |
| 163 | + /// @brief Subscribe to receive all messages to the specified topic. |
| 164 | + /// |
| 165 | + /// Subscribes an app instance to a topic, enabling it to receive messages |
| 166 | + /// sent to that topic. |
| 167 | + /// |
| 168 | + /// @param[in] topic The name of the topic to subscribe. Must match the |
| 169 | + /// following regular expression: `[a-zA-Z0-9-_.~%]{1,900}`. |
| 170 | + public static System.Threading.Tasks.Task SubscribeAsync(string topic) { |
| 171 | + return FirebaseMessagingInternal.SubscribeAsync(topic); |
| 172 | + } |
| 173 | + |
| 174 | + /// @brief Unsubscribe from a topic. |
| 175 | + /// |
| 176 | + /// Unsubscribes an app instance from a topic, stopping it from receiving |
| 177 | + /// any further messages sent to that topic. |
| 178 | + /// |
| 179 | + /// @param[in] topic The name of the topic to unsubscribe from. Must match the |
| 180 | + /// following regular expression: `[a-zA-Z0-9-_.~%]{1,900}`. |
| 181 | + public static System.Threading.Tasks.Task UnsubscribeAsync(string topic) { |
| 182 | + return FirebaseMessagingInternal.UnsubscribeAsync(topic); |
| 183 | + } |
| 184 | +} |
| 185 | + |
| 186 | +} // namespace Firebase.Messaging |
0 commit comments