Pusher Swift成员添加/删除了活动

时间:2016-04-04 19:37:24

标签: swift swift2 real-time pusher pusherswift

我现在正在使用Pusher Swift,但我找不到合适的方法来处理member_added和member_removed方法。在LibPusher(objective-c实现)中存在 PTPusherPresenceChannelDelegate 和memberAdded以及memberRemoved方法,但是在Pusher Swift中没有。

订阅它工作正常

let presenceChannel = pusher.subscribe("presence-channel")
    presenceChannel.bind("pusher:subscription_succeeded", callback: { (data: AnyObject?) -> Void in
        //It's ok!
    })

如何处理此事件?感谢

1 个答案:

答案 0 :(得分:3)

当您订阅在线频道时,您可以包含关闭以处理" onMemberAdded"和" onMemberRemoved"事件。

来自PusherSwift cocoapod docs

let onMemberAdded = { (member: PresenceChannelMember) in
    //Do something with the new member
    print(member)
}
let onMemberRemoved = { (member: PresenceChannelMember) in
    //Do something with the removed member
    print(member)
}
let chan = pusher.subscribe("presence-channel", onMemberAdded: onMemberAdded, onMemberRemoved: onMemberRemoved)