###前提・実現したいこと
multipeerconectivityを使用して2端末間で通信を行いたいのですが、通信を確立させた後に、画面遷移を行って、遷移先の画面でデータのやり取りを行いたくて、MCSessionの変数をappdelegateに書いたのですが、Viewcontroller.swiftにエラーが出てきて困っています。
どなたか教えてください。
###発生している問題・エラーメッセージ
Ambiguous reference to member 'session(_:peer:didChangeState:)'
###該当のソースコード
swift
1 2import UIKit 3import MultipeerConnectivity 4class ViewController: UIViewController,MCSessionDelegate,MCNearbyServiceBrowserDelegate,MCNearbyServiceAdvertiserDelegate { 5 6 let peer : MCPeerID = MCPeerID(displayName: UIDevice.currentDevice().name) 7 8 var browser : MCNearbyServiceBrowser? 9 var advertis : MCNearbyServiceAdvertiser? 10 let service = "p2p" 11 var appdelegate = UIApplication.sharedApplication().delegate as! AppDelegate 12 13 override func viewDidLoad() { 14 //self.session = MCSession(peer: peer) 15 //self.session!.delegate = self 16 self.browser = MCNearbyServiceBrowser(peer: peer, serviceType: service) 17 self.browser!.delegate = self 18 self.advertis = MCNearbyServiceAdvertiser(peer: peer, discoveryInfo: nil, serviceType: service) 19 self.advertis?.delegate = self 20 super.viewDidLoad() 21 22 } 23 24 override func didReceiveMemoryWarning() { 25 super.didReceiveMemoryWarning() 26 } 27 28 @IBAction func browser(sender: AnyObject) { 29 30 self.browser!.startBrowsingForPeers() 31 } 32 33 @IBAction func advertiser(sender: AnyObject) { 34 self.advertis!.startAdvertisingPeer() 35 } 36 func browser(browser: MCNearbyServiceBrowser, foundPeer peerID: MCPeerID, withDiscoveryInfo info: [String : String]?) { 37 print("[MCNearbyServiceBrowserDelegate] browser:foundPeer:withDiscoveryInfo:") 38 print(" + peerID = \(peerID.displayName)") 39 print(" + info = \(info)") 40 //browser.invitePeer(peerID, toSession: self.session!, withContext: nil, timeout: 10) 41 } 42 43 func browser(browser: MCNearbyServiceBrowser, lostPeer peerID: MCPeerID) { 44 print("[MCNearbyServiceBrowserDelegate] browser:lostPeer:") 45 print(" + peerID = \(peerID.displayName)") 46 } 47 48 49 func advertiser(advertiser: MCNearbyServiceAdvertiser, didReceiveInvitationFromPeer peerID: MCPeerID, withContext context: NSData?, invitationHandler: (Bool, MCSession) -> Void) { 50 print("[MCNearbyServiceAdvertiserDelegate] advertiser:didReceiveInvitationFromPeer:withContext:invitationHandler:") 51 print(" + peerID = \(peerID.displayName)") 52 53 let alert = UIAlertController(title: "招待を受けました", message: "from \(peerID.displayName)", preferredStyle: .Alert) 54 alert.addAction(UIAlertAction(title: "参加", style: .Default) { action in 55 //invitationHandler(true, self.session!) 56 }) 57 alert.addAction(UIAlertAction(title: "拒否", style: .Cancel) { action in 58 //invitationHandler(false, self.session!) 59 }) 60 self.presentViewController(alert, animated: true, completion: nil) 61 } 62 func session(session: MCSession, peer peerID: MCPeerID, didChangeState state: MCSessionState) { 63 let viewcontroller = self.storyboard!.instantiateViewControllerWithIdentifier("view2") 64 self.presentViewController(viewcontroller,animated: true,completion: nil) 65 print("change window") 66 67 } 68 func session(session: MCSession, didReceiveData data: NSData, fromPeer peerID: MCPeerID) { 69 print("receivedData") 70 } 71 72 func session(session: MCSession, didReceiveStream stream: NSInputStream, withName streamName: String, fromPeer peerID: MCPeerID) { 73 } 74 75 func session(session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, withProgress progress: NSProgress) { 76 } 77 78 func session(session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, atURL localURL: NSURL, withError error: NSError?) { 79 } 80 81} 82
import UIKit import MultipeerConnectivity @UIApplicationMain class AppDelegate: UIResponder,UIApplicationDelegate { var window: UIWindow? var session : MCSession? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. return true } func applicationWillResignActive(application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } func applicationDidEnterBackground(application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } func applicationWillEnterForeground(application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } func applicationDidBecomeActive(application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } func applicationWillTerminate(application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } }
###試したこと
インターネットで方法を探しましたが、わかりませんでした
###補足情報(言語/FW/ツール等のバージョンなど)
プログラム文は上がViewcontroller.swift
下がappdelegate.swiftです。
コメントアウトしている場所にエラーが出ています。
エラー内容は同じです。
わかりにくいかもしれませんが宜しくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/11 04:53