-
Notifications
You must be signed in to change notification settings - Fork 14
Publish Subscribe on iOS
Guillaume Gendre edited this page Jun 7, 2019
·
5 revisions
This page is part of the Cobalt Publish/Subscribe pages. Don't miss the others.
- Introduction to Cobalt PubSub messages
- Publish/Subscribe on the Web side
- Publish/Subscribe on Android
- Web Lifecycle messages
first, import the Cobalt class in your .h file :
#import <Cobalt/Cobalt.h>
-
message
: (NSDictionary) The message that will be sent in the channel. -
channel
: (string) The name of the channel in which you want to send your message.
[Cobalt publishMessage:@{@"myValue": @42}
toChannel:@"myChannel"];
Subscribe needs a delegate to catch the message. Add the delegate to your class :
@interface MyClass : MyParentClass <PubSubDelegate>
-
channel
: (string) The name of the channel you want to subscribe. -
delegate
: (PubSubDelegate) A Cobalt PubSubDelegate to handle the messages when they'll come. This PubSubDelegate has one methoddidReceiveMessage
receiving message and channel.
@implementation MyClass {
...
// later somewhere :
- (void)myFunction:() {
[Cobalt subscribeDelegate:self
toChannel:@"myChannel"];
}
...
// later again :
- (void)didReceiveMessage:(nullable NSDictionary *)message
onChannel:(nonnull NSString *)channel {
if ([channel isEqualToString:@"myChannel"]) {
// Do something with the message
}
}
Unsubscribe a PubSubDelegate to messages from the specified channel.
-
channel
: (string) The name of the channel you want to unsubscribe. -
delegate
: (PubSubDelegate) The Cobalt PubSubDelegate you used to handle the messages.
[Cobalt unsubscribeDelegate:self
fromChannel:@"myChannel"];
Cobalt is an Open-Source Hybrid Mobile Framework. Read more about it on the home page or in the documentation
- Introduction to Cobalt navigation
- The cobalt.json file
- native navigation bars
- Handling the Android back button
- Introduction to Cobalt messages
- Publish/Subscribe on the Web side
- Publish/Subscribe on Android
- Publish/Subscribe on iOS
- Web Lifecycle messages
- Pull-To-Refresh and Infinite Scroll
- Custom alerts and Toasts
- LocalStorage
- OpenExternalUrl
- PlatformInfos
- Ajax
- Removing the top bar
- Adding Cobalt to an existing project
- Customizing your hybrid views
- Handle multiple Cobalt webviews on the same screen (TODO)