Created
March 3, 2016 01:50
-
-
Save MariuszWisniewski/800f378f4a34c2f1d9b7 to your computer and use it in GitHub Desktop.
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
// | |
// ViewController.swift | |
// iOS | |
// | |
// Created by Mariusz Wisniewski on 2/18/16. | |
// Copyright © 2016 Mariusz Wisniewski. All rights reserved. | |
// | |
import UIKit | |
import syncano_ios | |
class ChannelDelegate : NSObject, SCChannelDelegate { | |
var roomName : String? = nil | |
func chanellDidReceivedNotificationMessage(notificationMessage: SCChannelNotificationMessage!) { | |
switch(notificationMessage.action) { | |
case .Create: | |
print("ROOM: \(roomName), Added new object, payload: \(notificationMessage.payload)") | |
case .Update: | |
print("ROOM: \(roomName), Updated object, payload: \(notificationMessage.payload)") | |
case .Delete: | |
print("ROOM: \(roomName), Deleted object, payload: \(notificationMessage.payload)") | |
case .None: | |
print("ROOM: \(roomName), Custom, payload: \(notificationMessage.payload)") | |
} | |
} | |
init(roomName: String) { | |
self.roomName = roomName | |
super.init() | |
} | |
} | |
class ViewController: UIViewController { | |
let syncano = Syncano.sharedInstanceWithApiKey("API_KEY", instanceName: "INSTANCE_NAME") | |
let channel_1 = SCChannel(name: "channel_with_rooms") | |
let channel_2 = SCChannel(name: "channel_with_rooms") | |
let channel_3 = SCChannel(name: "channel_with_rooms") | |
let channelName = "channel_with_rooms" | |
let roomName_1 = "room_1" | |
let roomName_2 = "room_2" | |
let roomName_3 = "room_3" | |
let delegate_1 = ChannelDelegate(roomName: "room_1") | |
let delegate_2 = ChannelDelegate(roomName: "room_2") | |
let delegate_3 = ChannelDelegate(roomName: "room_3") | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
self.testChannels() | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} | |
// MARK: Channel testing | |
extension ViewController { | |
func initChannels() { | |
self.channel_1.room = roomName_1 | |
self.channel_2.room = roomName_2 | |
self.channel_3.room = roomName_3 | |
self.channel_1.delegate = delegate_1 | |
self.channel_2.delegate = delegate_2 | |
self.channel_3.delegate = delegate_3 | |
// try commenting one of them - if you, you will receive notifications | |
// only from the rooms you subscribed to | |
self.channel_1.subscribeToChannel() | |
self.channel_2.subscribeToChannel() | |
self.channel_3.subscribeToChannel() | |
} | |
func testChannels() { | |
self.initChannels() | |
let test_1 = Test() | |
test_1.name = "1" | |
test_1.channel = channelName | |
test_1.channel_room = roomName_1 | |
let test_2 = Test() | |
test_2.name = "2" | |
test_2.channel = channelName | |
test_2.channel_room = roomName_2 | |
let test_3 = Test() | |
test_3.name = "3" | |
test_3.channel = channelName | |
test_3.channel_room = roomName_3 | |
test_1.saveWithCompletionBlock({_ in }) | |
test_2.saveWithCompletionBlock({_ in }) | |
test_3.saveWithCompletionBlock({_ in }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment