gpt4 book ai didi

ios - 另一个点接收到的 PeerID 对象与 MultipeerConnectivity Framework 中的原始对象不同

转载 作者:行者123 更新时间:2023-11-28 13:21:44 32 4
gpt4 key购买 nike

我正在使用 Multipeer Connectivity 框架。我将我的 PeerId 保存在 NSUserDefaults 中以像这样重用它(按照 Apple 的建议)(以下代码是快速的,但 Objective c 也具有相同的行为)。 :

        var peerId: MCPeerID = {
let defaults = NSUserDefaults.standardUserDefaults();
let dataToShow = defaults.dataForKey("kPeerID");
var peer = NSKeyedUnarchiver.unarchiveObjectWithData(dataToShow) as? MCPeerID;
if peer == nil {
peer = MCPeerID(displayName: UIDevice.currentDevice().name);
let data: NSData = NSKeyedArchiver.archivedDataWithRootObject(peer);
defaults.setObject(data, forKey: "kPeerID");
defaults.synchronize();
}
println("I am peer: \(peer!)");
return peer!;
}()

我像这样向发现的对等方发送邀请:

func browser(browser: MCNearbyServiceBrowser!, foundPeer peerID: MCPeerID!, withDiscoveryInfo info: [NSObject : AnyObject]!) {    
println("\(self.peerId) Found peer \(peerID)");
if let browserSession = self.session {
browserSession.delegate = self;
browser.invitePeer(peerID, toSession: browserSession, withContext: nil, timeout: 30);
}else {
println("Browser session is nil");
}
}

广告商使用代码找到它:

func advertiser(advertiser: MCNearbyServiceAdvertiser!, didReceiveInvitationFromPeer peerID: MCPeerID!, withContext context: NSData!, invitationHandler: ((Bool, MCSession!) -> Void)!) {
println("\(self.peerId) Received Invitation from \(peerID)");
var session = availableSession();
invitationHandler(true, session);
}

我面临的问题是:当广告商找到 peerId 时,它显示的 peerId 与原始 peerId 不同,但具有正确的显示名称。

浏览器控制台输出为:

  I am peer: <MCPeerID: 0x1663e670 DisplayName = Jon Yang’s iPad>
<MCPeerID: 0x1663e670 DisplayName = Jon Yang’s iPad> Received Invitation from <MCPeerID: 0x1666daf0 DisplayName = Jon Yang’s iPadMini>
<MCPeerID: 0x1663e670 DisplayName = Jon Yang’s iPad> Connecting with <MCPeerID: 0x1666daf0 DisplayName = Jon Yang’s iPadMini>
<MCPeerID: 0x1663e670 DisplayName = Jon Yang’s iPad> Connected with <MCPeerID: 0x1666daf0 DisplayName = Jon Yang’s iPadMini>

广告商控制台输出为:

 I am peer: <MCPeerID: 0x1569d230 DisplayName = Jon Yang’s iPadMini>
<MCPeerID: 0x1569d230 DisplayName = Jon Yang’s iPadMini> Found peer <MCPeerID: 0x15586600 DisplayName = Jon Yang’s iPad>
<MCPeerID: 0x1569d230 DisplayName = Jon Yang’s iPadMini> Connecting with <MCPeerID: 0x15586600 DisplayName = Jon Yang’s iPad>
<MCPeerID: 0x1569d230 DisplayName = Jon Yang’s iPadMini> Connected with <MCPeerID: 0x15586600 DisplayName = Jon Yang’s iPad>

正如你所看到的,即使 Browser 和 Advertiser 有它们的 peerId 信息,当它们被其他 peer 接收时,它们的 peerId 是不同的。谁能解释一下?我做错了什么吗?

最佳答案

 <MCPeerID: 0x1663e670 DisplayName = Jon Yang’s iPad>

0x1663e670表示MCPeerID对象在当前设备上的内存地址。不要将它与框架引用的实际 MCPeerID 对象混淆。只要 displayName 符合预期,那么它就是正确的对等点。

关于ios - 另一个点接收到的 PeerID 对象与 MultipeerConnectivity Framework 中的原始对象不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24943686/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com