MultipeerConnectivity MCPeerID displayName错误

时间:2016-03-16 11:52:31

标签: ios iphone xcode ipad

设置MultipeerConnectivity时出现以下错误:命令/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc因退出代码1而失败。

获取设备显示名称时会导致错误 - 任何想法?

 import UIKit
 import MultipeerConnectivity
 import MessageUI
 import AVFoundation

 class Selection: UIViewController, UIPickerViewDelegate,UIPickerViewDataSource, UITextFieldDelegate, UIImagePickerControllerDelegate, MCSessionDelegate, MCBrowserViewControllerDelegate {

  let serviceType = "testApp"
  var browser : MCBrowserViewController!
  var assistant : MCAdvertiserAssistant!
  var session : MCSession!
  var peerID: MCPeerID?


    override func viewDidLoad() {
    super.viewDidLoad()

    self.picker.delegate = self
    self.picker.dataSource = self

    // this line causes the error
    peerID = MCPeerID(displayName: UIDevice.currentDevice().name) 
    print("peerID = \(peerID)")

    session = MCSession(peer: self.peerID!, securityIdentity: nil,  encryptionPreference: MCEncryptionPreference.None)
    session = MCSession(peer:peerID!, securityIdentity: nil, encryptionPreference: MCEncryptionPreference.None)
    session?.delegate = self
    print("self.peerID = \(self.peerID)")
    self.session = MCSession(peer: peerID!)
    self.session.delegate = self

}

0 个答案:

没有答案