You must have a pubnub account to use the API. http://www.pubnub.com/account
PubNub is a Massively Scalable Real-time Service for Web and Mobile Games. This is a cloud-based service for broadcasting Real-time bidirectional messages to web, mobile, TV, tablet and GPS clients.
The PubNub Objective C Real-time Cloud Push API runs on Cocoa Native and Mobile Devices. This library offers complete non-blocking asynchronous message passing in the cloud.
The PubNub Real-time Cloud Push Service works with every mobile device using any carrier service provider.
http://github.com/pubnub/pubnub-api/tree/master/objective-c/
Pubnub *pubnub = [[Pubnub alloc]
publishKey: @"demo"
subscribeKey: @"demo"
secretKey: @"demo"
sslOn: NO
origin: @"pubsub.pubnub.com"
];
[pubnub
publish: @"hello_world_objective_c"
message: [NSDictionary
dictionaryWithObjectsAndKeys:
@"Star", @"first_name",
@"Salzman", @"last_name",
99999, @"awesomeness",
nil]
deligate: [Response alloc]
];
@interface PublishResponse: Response @end
@implementation PublishResponse
-(void) callback: (NSArray*) response {
NSLog( @"%@", response );
}
-(void) fail: (id) response {
NSLog( @"%@", response );
}
@end
int main( int argc, const char *argv[] ) {
Pubnub *pubnub = [[Pubnub alloc]
publishKey: @"demo"
subscribeKey: @"demo"
secretKey: @"demo"
sslOn: NO
origin: @"pubsub.pubnub.com"
];
// NSArray Example
[pubnub
publish: @"hello_world_objective_c"
message: [NSArray arrayWithObjects:
@"one",
@"two",
@"three",
nil
]
deligate: [PublishResponse alloc]
];
// NSDictionary Example
[pubnub
publish: @"hello_world_objective_c"
message: [NSDictionary
dictionaryWithObjectsAndKeys:
@"Star", @"first_name",
@"Salzman", @"last_name",
99999, @"awesomeness",
nil]
deligate: [PublishResponse alloc]
];
// Only necessary when running command line application.
[[NSRunLoop currentRunLoop] run];
// Free Pubnub
[pubnub release];
return 0;
}
[pubnub
subscribe: @"hello_world_objective_c"
deligate: [[SubscribeResponse alloc]
pubnub: pubnub
channel: @"hello_world_objective_c"
]
];
@interface SubscribeResponse: Response @end
@implementation SubscribeResponse
-(void) callback: (id) response {
NSLog( @"Received Message (channel: '%@') -> %@", channel, response );
}
@end
int main( int argc, const char *argv[] ) {
Pubnub *pubnub = [[Pubnub alloc]
publishKey: @"demo"
subscribeKey: @"demo"
secretKey: @"demo"
sslOn: NO
origin: @"pubsub.pubnub.com"
];
NSLog( @"Listening to: %@", @"hello_world_objective_c" );
[pubnub
subscribe: @"hello_world_objective_c"
deligate: [[SubscribeResponse alloc]
pubnub: pubnub
channel: @"hello_world_objective_c"
]
];
// Only necessary when running command line application.
[[NSRunLoop currentRunLoop] run];
// Free Pubnub
[pubnub release];
return 0;
}
[pubnub
history: @"hello_world_objective_c"
limit: 10
deligate: [HistoryResponse alloc]
];
@interface HistoryResponse: Response @end
@implementation HistoryResponse
-(void) callback: (NSArray*) response {
id message;
NSEnumerator* messages = [response objectEnumerator];
while ((message = [messages nextObject])) {
NSLog( @"%@", message );
}
}
@end
int main( int argc, const char *argv[] ) {
Pubnub *pubnub = [[Pubnub alloc]
publishKey: @"demo"
subscribeKey: @"demo"
secretKey: @"demo"
sslOn: NO
origin: @"pubsub.pubnub.com"
];
[pubnub
history: @"hello_world_objective_c"
limit: 10
deligate: [HistoryResponse alloc]
];
// Only necessary when running command line application.
[[NSRunLoop currentRunLoop] run];
// Free Pubnub
[pubnub release];
return 0;
}
[pubnub time: [TimeResponse alloc]];
@interface TimeResponse: TimeDelegate @end
@implementation TimeResponse
-(void) callback: (NSNumber*) response {
NSLog( @"%@", response );
}
@end
int main( int argc, const char *argv[] ) {
Pubnub *pubnub = [[Pubnub alloc]
publishKey: @"demo"
subscribeKey: @"demo"
secretKey: @"demo"
sslOn: NO
origin: @"pubsub.pubnub.com"
];
[pubnub time: [TimeResponse alloc]];
// Only necessary when running command line application.
[[NSRunLoop currentRunLoop] run];
// Free Pubnub
[pubnub release];
return 0;
}
- Copy PubNub directory into your XCode Project Class Directory.
- #import "pubnub.h"
- Refer to example.m for PubNub Usage Example.
- Copy PubNub directory into your Project Directory.
- #import "pubnub.h"
- Refer to example.m for PubNub Usage Example.
- Run ./build-example
- This will build example.m with a basic test of PubNub functions.