0

我有一个实现 MCNearbyServiceAdvertiserDelegate 的类。在初始化时,如果我调用 MPCManager.advertiser.startadvertisingpeer(),我可以从客户端看到广告的对等点。我正在尝试实施一种方法来停止广告,更改广告商discoveryInfo,然后使用新的发现信息再次开始广告。

这些方法成功地停止了广告对等方,但它不会再次开始广告。你能帮我解决这个问题吗

代码详情

classMPCManager:NSObject,MCSessionDelegate,MCNearbyServiceBrowserDelegate, MCNearbyServiceAdvertiserDelegate {

var delegate: MPCManagerDelegate?

var session: MCSession!
var sessionList: [MCSession]! = []
var peer: MCPeerID!

var browser: MCNearbyServiceBrowser!

var advertiser: MCNearbyServiceAdvertiser!

var foundPeers:[NSDictionary]! = [] 

var invitationHandler: ((Bool, MCSession!)->Void)!

var discoveryInfo:[String: String]!

init(discoveryInfo:[String:String]!, peer:MCPeerID!) {
    super.init()
    self.discoveryInfo = discoveryInfo
    self.peer = peer
    session = MCSession(peer: self.peer)
    session.delegate = self
    browser = MCNearbyServiceBrowser(peer: peer, serviceType: "myservicetype")
    browser.delegate = self
    advertiser = MCNearbyServiceAdvertiser(peer: self.peer, discoveryInfo: self.discoveryInfo, serviceType: "myservicetype")
    advertiser.delegate = self
}
 /////some other methods
///the problematic method
 func setAdvertising(discoveryInfo:[String:String]!){
    print("setting advertising")
    self.discoveryInfo = discoveryInfo
    advertiser.stopAdvertisingPeer()
    advertiser = nil
    self.advertiser =  MCNearbyServiceAdvertiser(peer: self.peer, discoveryInfo: self.discoveryInfo, serviceType: "myservicetype")
   self.advertiser.delegate = self
   print("advertising from set advertising")
   advertiser.startAdvertisingPeer()
 }
4

1 回答 1

0

最后让它工作。我在另一篇文章中寻求使用发现信息作为字典而不是 [String:String] 奇怪的东西,但它现在可以工作了:D!。感谢所有花时间阅读的人

于 2015-11-10T07:10:19.630 回答