Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added presence test and more command line examples

  • Loading branch information...
commit 362c40a7358f666ed8c9adf27e13eb2fb3b6da3a 1 parent ea018c6
Igor Tryus authored
View
1  cocoa/3.3/CocoaPubnubTest/CocoaPubnubTest/AppDelegate.h
@@ -26,6 +26,7 @@
- (IBAction)unsubscribe_81_test:(id)sender;
- (IBAction)here_now_81_test:(id)sender;
- (IBAction)uuid_81_test:(id)sender;
+- (IBAction) presence_81_test:(id)sender;
@end
View
5 cocoa/3.3/CocoaPubnubTest/CocoaPubnubTest/AppDelegate.m
@@ -59,6 +59,11 @@ - (IBAction)time_81_test:(id)sender{
- (IBAction)subscribe_CL_81_test:(id)sender{
[cl_81_test subscribe];
}
+
+- (IBAction) presence_81_test:(id)sender {
+ [cl_81_test presence];
+}
+
- (IBAction)unsubscribe_81_test:(id)sender {
[cl_81_test unsubscribe];
}
View
1  cocoa/3.3/CocoaPubnubTest/CocoaPubnubTest/UnitTest/CL_81.h
@@ -16,6 +16,7 @@
- (void) getTime;
- (void) getUUID;
- (void) subscribe;
+- (void) presence;
- (void) unsubscribe;
- (void) here_now;
View
10 cocoa/3.3/CocoaPubnubTest/CocoaPubnubTest/UnitTest/CL_81.m
@@ -57,6 +57,11 @@ - (void) subscribe
[pubnub subscribe: _channel];
}
+- (void) presence
+{
+ [pubnub presence: _channel];
+}
+
- (void) unsubscribe
{
[pubnub unsubscribeFromChannel: _channel];
@@ -129,6 +134,11 @@ - (void)pubnub:(CEPubnub *)pubnub reconnectToChannel:(NSString *)channel{
NSLog(@"Re-Connect to Channel: %@",channel);
}
+- (void)pubnub:(CEPubnub *)pubnub presence:(NSDictionary *)message onChannel:(NSString *)channel
+{
+ NSLog(@"channel:%@ \npresence- %@",channel,message);
+}
+
/*HERE NOW callback*/
- (void)pubnub:(CEPubnub *)pubnub hereNow:(NSDictionary *)message onChannel:(NSString *)channel
View
181 cocoa/3.3/CocoaPubnubTest/CocoaPubnubTest/en.lproj/MainMenu.xib
@@ -1540,7 +1540,7 @@
<string key="NSFrame">{{14, 173}, {129, 32}}</string>
<reference key="NSSuperview" ref="439893737"/>
<reference key="NSWindow"/>
- <reference key="NSNextKeyView"/>
+ <reference key="NSNextKeyView" ref="577096236"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="938641649">
@@ -1559,6 +1559,31 @@
</object>
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
</object>
+ <object class="NSButton" id="577096236">
+ <reference key="NSNextResponder" ref="439893737"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{166, 173}, {135, 32}}</string>
+ <reference key="NSSuperview" ref="439893737"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSButtonCell" key="NSCell" id="341779967">
+ <int key="NSCellFlags">67108864</int>
+ <int key="NSCellFlags2">134217728</int>
+ <string key="NSContents">presence (CL-81)</string>
+ <reference key="NSSupport" ref="736376476"/>
+ <string key="NSCellIdentifier">_NS:9</string>
+ <reference key="NSControlView" ref="577096236"/>
+ <int key="NSButtonFlags">-2038284288</int>
+ <int key="NSButtonFlags2">129</int>
+ <string key="NSAlternateContents"/>
+ <string key="NSKeyEquivalent"/>
+ <int key="NSPeriodicDelay">200</int>
+ <int key="NSPeriodicInterval">25</int>
+ </object>
+ <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
+ </object>
</array>
<string key="NSFrameSize">{480, 360}</string>
<reference key="NSSuperview"/>
@@ -2338,6 +2363,14 @@
</object>
<int key="connectionID">697</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">presence_81_test:</string>
+ <reference key="source" ref="976324537"/>
+ <reference key="destination" ref="577096236"/>
+ </object>
+ <int key="connectionID">713</int>
+ </object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@@ -2975,6 +3008,54 @@
<float key="scoringTypeFloat">24</float>
<int key="contentType">2</int>
</object>
+ <object class="IBNSLayoutConstraint" id="667753852">
+ <reference key="firstItem" ref="577096236"/>
+ <int key="firstAttribute">9</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="113775017"/>
+ <int key="secondAttribute">9</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">0.0</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="439893737"/>
+ <int key="scoringType">6</int>
+ <float key="scoringTypeFloat">24</float>
+ <int key="contentType">2</int>
+ </object>
+ <object class="IBNSLayoutConstraint" id="61142817">
+ <reference key="firstItem" ref="577096236"/>
+ <int key="firstAttribute">5</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="439893737"/>
+ <int key="secondAttribute">5</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">172</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="439893737"/>
+ <int key="scoringType">3</int>
+ <float key="scoringTypeFloat">9</float>
+ <int key="contentType">3</int>
+ </object>
+ <object class="IBNSLayoutConstraint" id="840314303">
+ <reference key="firstItem" ref="577096236"/>
+ <int key="firstAttribute">11</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="641618729"/>
+ <int key="secondAttribute">11</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">0.0</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="439893737"/>
+ <int key="scoringType">6</int>
+ <float key="scoringTypeFloat">24</float>
+ <int key="contentType">2</int>
+ </object>
<object class="IBNSLayoutConstraint" id="235225984">
<reference key="firstItem" ref="373923042"/>
<int key="firstAttribute">5</int>
@@ -3023,22 +3104,6 @@
<float key="scoringTypeFloat">24</float>
<int key="contentType">2</int>
</object>
- <object class="IBNSLayoutConstraint" id="543100822">
- <reference key="firstItem" ref="113775017"/>
- <int key="firstAttribute">5</int>
- <int key="relation">0</int>
- <reference key="secondItem" ref="439893737"/>
- <int key="secondAttribute">5</int>
- <float key="multiplier">1</float>
- <object class="IBLayoutConstant" key="constant">
- <double key="value">175</double>
- </object>
- <float key="priority">1000</float>
- <reference key="containingView" ref="439893737"/>
- <int key="scoringType">3</int>
- <float key="scoringTypeFloat">9</float>
- <int key="contentType">3</int>
- </object>
<object class="IBNSLayoutConstraint" id="213377987">
<reference key="firstItem" ref="113775017"/>
<int key="firstAttribute">11</int>
@@ -3209,6 +3274,7 @@
<reference ref="893650074"/>
<reference ref="373923042"/>
<reference ref="641618729"/>
+ <reference ref="577096236"/>
</array>
<reference key="parent" ref="972006081"/>
</object>
@@ -3940,11 +4006,6 @@
<reference key="parent" ref="439893737"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">642</int>
- <reference key="object" ref="543100822"/>
- <reference key="parent" ref="439893737"/>
- </object>
- <object class="IBObjectRecord">
<int key="objectID">646</int>
<reference key="object" ref="373594629"/>
<array class="NSMutableArray" key="children">
@@ -4109,6 +4170,55 @@
<reference key="object" ref="758547900"/>
<reference key="parent" ref="439893737"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">698</int>
+ <reference key="object" ref="577096236"/>
+ <array class="NSMutableArray" key="children">
+ <reference ref="341779967"/>
+ <object class="IBNSLayoutConstraint" id="588542428">
+ <reference key="firstItem" ref="577096236"/>
+ <int key="firstAttribute">7</int>
+ <int key="relation">0</int>
+ <nil key="secondItem"/>
+ <int key="secondAttribute">0</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">123</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="577096236"/>
+ <int key="scoringType">3</int>
+ <float key="scoringTypeFloat">9</float>
+ <int key="contentType">1</int>
+ </object>
+ </array>
+ <reference key="parent" ref="439893737"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">699</int>
+ <reference key="object" ref="341779967"/>
+ <reference key="parent" ref="577096236"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">705</int>
+ <reference key="object" ref="840314303"/>
+ <reference key="parent" ref="439893737"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">710</int>
+ <reference key="object" ref="588542428"/>
+ <reference key="parent" ref="577096236"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">711</int>
+ <reference key="object" ref="61142817"/>
+ <reference key="parent" ref="439893737"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">712</int>
+ <reference key="object" ref="667753852"/>
+ <reference key="parent" ref="439893737"/>
+ </object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
@@ -4186,10 +4296,12 @@
<reference ref="609148026"/>
<reference ref="758547900"/>
<reference ref="213377987"/>
- <reference ref="543100822"/>
<reference ref="597045587"/>
<reference ref="189173015"/>
<reference ref="235225984"/>
+ <reference ref="840314303"/>
+ <reference ref="61142817"/>
+ <reference ref="667753852"/>
<reference ref="123580266"/>
<reference ref="108773710"/>
<reference ref="519979354"/>
@@ -4330,7 +4442,6 @@
<string key="625.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="639.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="640.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string key="642.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<array key="646.IBNSViewMetadataConstraints">
<reference ref="16311582"/>
</array>
@@ -4365,6 +4476,16 @@
<string key="693.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="695.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="696.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <array key="698.IBNSViewMetadataConstraints">
+ <reference ref="588542428"/>
+ </array>
+ <boolean value="NO" key="698.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
+ <string key="698.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="699.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="705.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="710.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="711.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="712.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="72.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="73.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="74.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -4381,7 +4502,7 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">697</int>
+ <int key="maxID">713</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -4390,12 +4511,12 @@
<string key="superclassName">NSObject</string>
<dictionary class="NSMutableDictionary" key="actions">
<string key="CL_223_UnitTest:">id</string>
- <string key="CL_81_test:">id</string>
<string key="Catch_up_Click:">id</string>
<string key="DetailedHistoryUbitTest:">id</string>
<string key="UnsubscribeUnitTest:">id</string>
<string key="here_now_81_test:">id</string>
<string key="history_81_test:">id</string>
+ <string key="presence_81_test:">id</string>
<string key="publish_CL_81_test:">id</string>
<string key="subscribe_CL_81_test:">id</string>
<string key="time_81_test:">id</string>
@@ -4407,10 +4528,6 @@
<string key="name">CL_223_UnitTest:</string>
<string key="candidateClassName">id</string>
</object>
- <object class="IBActionInfo" key="CL_81_test:">
- <string key="name">CL_81_test:</string>
- <string key="candidateClassName">id</string>
- </object>
<object class="IBActionInfo" key="Catch_up_Click:">
<string key="name">Catch_up_Click:</string>
<string key="candidateClassName">id</string>
@@ -4431,6 +4548,10 @@
<string key="name">history_81_test:</string>
<string key="candidateClassName">id</string>
</object>
+ <object class="IBActionInfo" key="presence_81_test:">
+ <string key="name">presence_81_test:</string>
+ <string key="candidateClassName">id</string>
+ </object>
<object class="IBActionInfo" key="publish_CL_81_test:">
<string key="name">publish_CL_81_test:</string>
<string key="candidateClassName">id</string>
View
82 cocoa/3.3/PubNub/cocoa/PubNub/cl-81-example.m
@@ -1,15 +1,49 @@
#import "CEPubnubDelegate.h"
#import "CEPubnub.h"
-@interface PublishResponse : NSObject <CEPubnubDelegate> @end
+@interface CEPubnubResponse : NSObject <CEPubnubDelegate> @end
+
+@implementation CEPubnubResponse
-@implementation PublishResponse
- (void)pubnub:(CEPubnub *)pubnub didSucceedPublishingMessageToChannel:(NSString *)channel
withResponse:(id)response
message:(id)message
{
NSLog(@"Sent message to PubNub channel \"%@\" \n%@ \nSent Message:%@", channel, response, message);
}
+
+- (void)pubnub:(CEPubnub *)pubnub didReceiveTime:(NSTimeInterval)time{
+ NSLog(@"didReceiveTime %f",time );
+}
+
+- (void)pubnub:(CEPubnub *)pubnub presence:(NSDictionary *)message onChannel:(NSString *)channel
+{
+ NSLog(@"channel:%@ \npresence- %@",channel,message);
+}
+
+- (void)pubnub:(CEPubnub *)pubnub subscriptionDidReceiveString:(NSString *)message onChannel:(NSString *)channel
+{
+ NSLog(@"Subscribe %@",message);
+}
+
+- (void)pubnub:(CEPubnub *)pubnub didFetchHistory:(NSArray *)messages forChannel:(NSString *)channel{
+ int i=0;
+
+ NSMutableString *histry= [NSMutableString stringWithString: @""];
+ for (NSString *object in messages) {
+ NSLog(@"%d \n%@",i,object);
+ [histry appendString:[NSString stringWithFormat:@" %i\n%@",i,object]];
+ i++;
+ }
+ NSLog(@"History on channel (dict) : %@ - received:\n %@", channel, histry);
+
+}
+
+- (void)pubnub:(CEPubnub *)pubnub hereNow:(NSDictionary *)message onChannel:(NSString *)channel
+{
+ NSLog(@"here_now- %@",message);
+}
+
@end
CEPubnub *pubnub;
@@ -21,14 +55,48 @@ int main( int argc, const char *argv[] ) {
// ------------------
CEPubnub *pubnub = [[CEPubnub alloc] initWithPublishKey:@"demo" subscribeKey:@"demo" secretKey:nil cipherKey:nil useSSL:NO];
- [pubnub setDelegate:[PublishResponse alloc]];
- // -------------------------------------
- // PubNub Publish Message (Send Message)
- // -------------------------------------
- NSLog(@"-----------PUBLISH STRING----------------");
+ [pubnub setDelegate:[CEPubnubResponse alloc]];
+
+// ----------------------------------
+// PubNub Server Time (Get TimeToken)
+// ----------------------------------
+ [pubnub getTime];
+
+// -----------------------------------
+// PubNub presence
+// -----------------------------------
+ NSLog( @"Presence to: %@", channelName );
+ [pubnub presence: channelName];
+
+// -----------------------------------
+// PubNub Subscribe (Receive Messages)
+// -----------------------------------
+ NSLog( @"Listening to: %@", channelName );
+ [pubnub subscribe: channelName];
+
+// ---------------------------------------
+// PubNub History (Recent Message History)
+// ---------------------------------------
+ NSInteger limit = 3;
+ NSNumber * aWrappedInt = [NSNumber numberWithInteger:limit];
+ [pubnub fetchHistory:[NSDictionary dictionaryWithObjectsAndKeys: aWrappedInt,@"limit", channelName,@"channel",nil]];
+
+// -------------------------------------
+// PubNub Publish Message (Send Message)
+// -------------------------------------
NSString *text=@"Hello World";
[pubnub publish:[NSDictionary dictionaryWithObjectsAndKeys:channelName,@"channel",text,@"message", nil]];
+// -----------------------------------
+// Here Now
+// -----------------------------------
+ [pubnub hereNow:channelName];
+
+// -----------------------------------
+// unsubscribe from all channels
+// -----------------------------------
+ [pubnub unsubscribeFromChannel: nil];
+
// ----------------------------------
// Run Loop for Asynchronous Requests
// ----------------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.