aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Messaging/FIRMessagingPubSub.h
diff options
context:
space:
mode:
authorGravatar Paul Beusterien <paulbeusterien@google.com>2017-05-15 12:27:07 -0700
committerGravatar Paul Beusterien <paulbeusterien@google.com>2017-05-15 12:27:07 -0700
commit98ba64449a632518bd2b86fe8d927f4a960d3ddc (patch)
tree131d9c4272fa6179fcda6c5a33fcb3b1bd57ad2e /Firebase/Messaging/FIRMessagingPubSub.h
parent32461366c9e204a527ca05e6e9b9404a2454ac51 (diff)
Initial
Diffstat (limited to 'Firebase/Messaging/FIRMessagingPubSub.h')
-rw-r--r--Firebase/Messaging/FIRMessagingPubSub.h148
1 files changed, 148 insertions, 0 deletions
diff --git a/Firebase/Messaging/FIRMessagingPubSub.h b/Firebase/Messaging/FIRMessagingPubSub.h
new file mode 100644
index 0000000..3a03494
--- /dev/null
+++ b/Firebase/Messaging/FIRMessagingPubSub.h
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2017 Google
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#import "FIRMessagingTopicsCommon.h"
+
+@class FIRMessagingClient;
+@class FIRMessagingPubSubCache;
+
+/**
+ * FIRMessagingPubSub provides a publish-subscribe model for sending FIRMessaging topic messages.
+ *
+ * An app can subscribe to different topics defined by the
+ * developer. The app server can then send messages to the subscribed devices
+ * without having to maintain topic-subscribers mapping. Topics do not
+ * need to be explicitly created before subscribing or publishing&mdash;they
+ * are automatically created when publishing or subscribing.
+ *
+ * Messages published to the topic will be received as regular FIRMessaging messages
+ * with `"from"` set to `"/topics/myTopic"`.
+ *
+ * Only topic names that match the pattern `"/topics/[a-zA-Z0-9-_.~%]{1,900}"`
+ * are allowed for subscribing and publishing.
+ */
+@interface FIRMessagingPubSub : NSObject
+
+@property(nonatomic, readonly, strong) FIRMessagingPubSubCache *cache;
+@property(nonatomic, readonly, strong) FIRMessagingClient *client;
+
+/**
+ * Initializes an instance of FIRMessagingPubSub.
+ *
+ * @return An instance of FIRMessagingPubSub.
+ */
+- (instancetype)initWithClient:(FIRMessagingClient *)client NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Subscribes an app instance to a topic, enabling it to receive messages
+ * sent to that topic.
+ *
+ * This is an asynchronous call. If subscription fails, FIRMessaging
+ * invokes the completion callback with the appropriate error.
+ *
+ * @see FIRMessagingPubSub unsubscribeWithToken:topic:handler:
+ *
+ * @param token The registration token as received from the InstanceID
+ * library for a given `authorizedEntity` and "gcm" scope.
+ * @param topic The topic to subscribe to. Should be of the form
+ * `"/topics/<topic-name>"`.
+ * @param handler The callback handler invoked when the subscribe call
+ * ends. In case of success, a nil error is returned. Otherwise,
+ * an appropriate error object is returned.
+ * @discussion This method is thread-safe. However, it is not guaranteed to
+ * return on the main thread.
+ */
+- (void)subscribeWithToken:(NSString *)token
+ topic:(NSString *)topic
+ options:(NSDictionary *)options
+ handler:(FIRMessagingTopicOperationCompletion)handler;
+
+
+/**
+ * Unsubscribes an app instance from a topic, stopping it from receiving
+ * any further messages sent to that topic.
+ *
+ * This is an asynchronous call. If the attempt to unsubscribe fails,
+ * we invoke the `completion` callback passed in with an appropriate error.
+ *
+ * @param token The token used to subscribe to this topic.
+ * @param topic The topic to unsubscribe from. Should be of the form
+ * `"/topics/<topic-name>"`.
+ * @param handler The handler that is invoked once the unsubscribe call ends.
+ * In case of success, nil error is returned. Otherwise, an
+ * appropriate error object is returned.
+ * @discussion This method is thread-safe. However, it is not guaranteed to
+ * return on the main thread.
+ */
+- (void)unsubscribeWithToken:(NSString *)token
+ topic:(NSString *)topic
+ options:(NSDictionary *)options
+ handler:(FIRMessagingTopicOperationCompletion)handler;
+
+/**
+ * Asynchronously subscribe to the topic. Adds to the pending list of topic operations.
+ * Retry in case of failures. This makes a repeated attempt to subscribe to the topic
+ * as compared to the `subscribe` method above which tries once.
+ *
+ * @param topic The topic name to subscribe to. Should be of the form `"/topics/<topic-name>"`.
+ */
+- (void)subscribeToTopic:(NSString *)topic;
+
+/**
+ * Asynchronously unsubscribe from the topic. Adds to the pending list of topic operations.
+ * Retry in case of failures. This makes a repeated attempt to unsubscribe from the topic
+ * as compared to the `unsubscribe` method above which tries once.
+ *
+ * @param topic The topic name to unsubscribe from. Should be of the form `"/topics/<topic-name>"`.
+ */
+- (void)unsubscribeFromTopic:(NSString *)topic;
+
+/**
+ * Schedule subscriptions sync.
+ *
+ * @param immediately YES if the sync should be scheduled immediately else NO if we can delay
+ * the sync.
+ */
+- (void)scheduleSync:(BOOL)immediately;
+
+/**
+ * Adds the "/topics/" prefix to the topic.
+ *
+ * @param topic The topic to add the prefix to.
+ *
+ * @return The new topic name with the "/topics/" prefix added.
+ */
++ (NSString *)addPrefixToTopic:(NSString *)topic;
+
+/**
+ * Check if the topic name has "/topics/" prefix.
+ *
+ * @param topic The topic name to verify.
+ *
+ * @return YES if the topic name has "/topics/" prefix else NO.
+ */
++ (BOOL)hasTopicsPrefix:(NSString *)topic;
+
+/**
+ * Check if it's a valid topic name. This includes "/topics/" prefix in the topic name.
+ *
+ * @param topic The topic name to verify.
+ *
+ * @return YES if the topic name satisfies the regex "/topics/[a-zA-Z0-9-_.~%]{1,900}".
+ */
++ (BOOL)isValidTopicWithPrefix:(NSString *)topic;
+
+@end