Last active
August 29, 2015 14:05
-
-
Save MariuszWisniewski/57dfe469ad0a2e944e70 to your computer and use it in GitHub Desktop.
Using Sync Server Basics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SYNViewController.h | |
// syncserver-ios-test | |
// | |
#import <UIKit/UIKit.h> | |
@interface SYNViewController : UIViewController | |
@end | |
//---------------------------------------------- | |
// | |
// SYNViewController.m | |
// syncserver-ios-test | |
// | |
#import "SYNViewController.h" | |
#import <Syncano.h> | |
#import <SyncanoSyncServer.h> | |
@interface SYNViewController ()<SyncanoSyncServerDelegate> | |
@property (strong, nonatomic) SyncanoSyncServer *syncServer; | |
@property (strong, nonatomic) UILabel *label; | |
@end | |
@implementation SYNViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
self.syncServer = [SyncanoSyncServer syncanoSyncServerForDomain:@"YOUR-DOMAIN" apiKey:@"YOUR-API-KEY"]; | |
self.syncServer.delegate = self; | |
NSError *error = nil; | |
[self.syncServer connect:&error]; | |
self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, CGRectGetWidth(self.view.bounds), 50)]; | |
self.label.textAlignment = NSTextAlignmentCenter; | |
[self.view addSubview:self.label]; | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
} | |
- (void)syncServerConnectionOpened:(SyncanoSyncServer *)syncServer { | |
NSLog(@"Sync Server Connection opened"); | |
//Use your own projectId and collectionId values | |
SyncanoParameters_Subscriptions_SubscribeCollection *params = [[SyncanoParameters_Subscriptions_SubscribeCollection alloc] initWithProjectId:@"12345" collectionId:@"678910" context:@"connection"]; | |
[self.syncServer sendRequest:params callback: ^(SyncanoResponse *response) { | |
NSLog(@"Subscription response: %@", response); | |
}]; | |
} | |
- (void)syncServer:(SyncanoSyncServer *)syncServer connectionClosedWithError:(NSError *)error { | |
NSLog(@"Sync Server Error: %@", error); | |
} | |
- (void)syncServer:(SyncanoSyncServer *)syncServer notificationAdded:(SyncanoData *)addedData { | |
NSLog(@"Added data: %@", addedData); | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
self.label.text = addedData.title; | |
}); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment