SlideShare a Scribd company logo
1 of 28
Download to read offline
CocoaHeads Taichung
2014.06.26
RAKI - 丫狸
iOS藍⽛牙內網技術
這是⽩白話⽂文
Multipeer Connectivity Framework
其實就是 iOS7 的
https://dl.dropboxusercontent.com/u/2857188/MCDemo.zip
Multipeer Connectivity Framework
以Blueooth或是Wi-Fi建設起近場網絡
使附近的設備可以彼此聯通
無需通過web server中介處理
相連的節點都能夠安全地傳輸
1 NSData 訊息資料
2 Resources ⽂文件檔案
3 Streaming data 影⾳音串流
在網狀網絡中,所有設備可以彼此直接通信,⽽而無需central hub
App 實例
Firechat
iOS
Android
iOS+Android
SDK-P2P網
個⼈人區域網路
NFC?
iBeacon? BLE?
Multipeer?
CoreBluetooth 低功耗藍⽛牙框架
Multipeer 網狀網絡框架
MCPeerID:周邊設備。
MCSession:內網會議室。
MCAdvertiserAssistant:廣播給附近的設備(快速版)。
MCBrowserViewController:搜尋附近的設備(快速版)。
MCNearbyServiceAdvertiser:廣播給附近的設備(實作版)。
MCNearbyServiceBrowser:搜尋附近的設備(實作版)。
CBCentralManager 搜尋/連線/處理資料(中央設備)
CBPeripheral 廣播/傳送/接收資料(外部設備)
快速對照
CoreBluetooth 低功耗藍⽛牙框架
Multipeer 網狀網絡框架
serviceType(指定連線服務)
foundPeer(發現外部設備)
didReceiveInvitationFromPeer(連接外部設備)
lostPeer(外部設備斷線)
scanForPeripheralsWithServices:nil(指定連線服務)
didDiscoverPeripheral(發現外部設備)
didConnectPeripheral(連接外部設備)
didDisconnectPeripheral(外部設備斷線)
快速對照
要進⼊入程式碼了!
新⼿手上場請多多包涵
1/5 Creating a Peer
_peerID = [[MCPeerID alloc] initWithDisplayName:displayName];
2/5 Creating a Session
_session = [[MCSession alloc] initWithPeer:_peerID];
_session.delegate = self;
3/5 內建廣播
_advertiser = [[MCAdvertiserAssistant alloc]
initWithServiceType:ServiceType
discoveryInfo:nil
session:_session];
[_advertiser start];
4/5 內建搜尋
_browser = [[MCBrowserViewController alloc]
initWithServiceType:ServiceType session:_session];
5/5 開啟⾯面板
[[[appDelegate mcManager] advertiser] setDelegate:self];
[[[appDelegate mcManager] browser] setDelegate:self];
!
[self presentViewController:[[appDelegate mcManager] browser]
animated:YES completion:
^{NSLog(@"打開browser");}];
MCBrowserViewControllerDelegate
-(void)browserViewControllerDidFinish:(MCBrowserViewController *)browserViewController
{
NSLog(@"完成browser");
[appDelegate.mcManager.browser dismissViewControllerAnimated:YES completion:nil];
}
!
-(void)browserViewControllerWasCancelled:(MCBrowserViewController *)browserViewController
{
NSLog(@"取消browser");
[appDelegate.mcManager.browser dismissViewControllerAnimated:YES completion:nil];
}
Demo:跨協定Peer互通
3/5 實作Advertising
appDelegate.mcManager.NearbyAdvertiser =
[[MCNearbyServiceAdvertiser alloc]
initWithPeer:appDelegate.mcManager.peerID
discoveryInfo:nil
serviceType:appDelegate.mcManager.ServiceType];
appDelegate.mcManager.NearbyAdvertiser.delegate = self;
[appDelegate.mcManager.NearbyAdvertiser startAdvertisingPeer];
4/5 實作Discovering
appDelegate.mcManager.NearbyBrowser =
[[MCNearbyServiceBrowser alloc]
initWithPeer:appDelegate.mcManager.peerID
serviceType:appDelegate.mcManager.ServiceType];
!
appDelegate.mcManager.NearbyBrowser.delegate = self;
[appDelegate.mcManager.NearbyBrowser startBrowsingForPeers];
5/5 實作⾃自訂介⾯面
剩下的交給MCSessionDelegate
foundPeer 函式可收集找到的設備
_session.connectedPeers 可列出已連線設備
-(void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:
(MCSessionState)state
{
NSLog(@"Session for peer: %@, changed state to: %i", peerID, (int)state);
//MCSessionStateNotConnected, // not in the session
//MCSessionStateConnecting, // connecting to this peer
//MCSessionStateConnected // connected to the session}
}
MCNearbyServiceBrowserDelegate
-(void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID
*)peerID withDiscoveryInfo:(NSDictionary *)info
{
if (![appDelegate.mcManager.session.connectedPeers containsObject:peerID]{
//TODO:直接邀請
[appDelegate.mcManager.NearbyBrowser
invitePeer:peerID
toSession:appDelegate.mcManager.session
withContext:nil
timeout:0.0];
}
MCNearbyServiceAdvertiserDelegate
- (void)advertiser:(MCNearbyServiceAdvertiser *)advertiser
didReceiveInvitationFromPeer:(MCPeerID *)peerID withContext:(NSData
*)context invitationHandler:(void(^)(BOOL accept, MCSession
*session))invitationHandler
{
//TODO:直接同意
!
或是
!
//TODO:⾃自訂詢問
}
MCNearbyServiceAdvertiserDelegate
//TODO:⾃自訂詢問
arrayInvitationHandler = [NSArray arrayWithObject:[invitationHandler
copy]];
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:peerID.displayName
message:@"Would like to create a session with you"
delegate:self
cancelButtonTitle:@"Decline"
otherButtonTitles:@"Accept", nil];
[alertView show];
//TODO:直接同意
invitationHandler(YES,appDelegate.mcManager.session);
UIAlertViewDelegate
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
BOOL accept = (buttonIndex != alertView.cancelButtonIndex) ? YES : NO;
//TODO:回答詢問
if(accept) {
NSLog(@"Session accept");
void (^invitationHandler)(BOOL, MCSession *) = [arrayInvitationHandler objectAtIndex:0];
invitationHandler(accept, appDelegate.mcManager.session);
}
else
{
NSLog(@"Session disallowed");
}
}
發送訊息
MCSessionDelegate
MCSessionDelegate
// Received data from remote peer
-(void)session:(MCSession *)session didReceiveData:(NSData *)data fromPeer:(MCPeerID *)peerID
{
NSString *message = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
!
NSDictionary *dict = @{@"data": data,@"peerID": peerID
};
[[NSNotificationCenter defaultCenter] postNotificationName:@"MCDidReceiveDataNotification"
object:nil
userInfo:dict];
}
MCSessionDelegate
// Start receiving a resource from remote peer
-(void)session:(MCSession *)session didStartReceivingResourceWithName:
(NSString *)resourceName fromPeer:(MCPeerID *)peerID withProgress:
(NSProgress *)progress
// Finished receiving a resource from remote peer
-(void)session:(MCSession *)session didFinishReceivingResourceWithName:
(NSString *)resourceName fromPeer:(MCPeerID *)peerID atURL:(NSURL
*)localURL withError:(NSError *)error
MCSessionDelegate
// Received a byte stream from remote peer
-(void)session:(MCSession *)session didReceiveStream:(NSInputStream
*)stream withName:(NSString *)streamName fromPeer:(MCPeerID *)peerID
{
NSLog(@"Session started receiving stream: %@ with name: %@ from peer:
%@", stream, streamName, peerID);
}
Demo:⽣生活應⽤用
⺫⽬目標同步 - 出遊規劃分⼯工同步
戰術指導 - 儲存下來還可以有回合制
延伸螢幕 - 再⼤大的投影機都還是有搖滾區
導覽解說 - 更⽣生動即時的旅遊回憶(個⼈人語⾳音導覽機偏向iBeacon)
點餐系統 - 不必架設server很多事都可以在⼩小型區域內快速達成
會議記錄 - 開完會⾼高校產出跨部會記錄表
互動教材 - 學習模式數位化,資料收集可排除網路環境的限制
感謝聆聽
RAKI - 丫狸
raki-fox@msn.com

More Related Content

Similar to 2014.06.26 CocoaHeads - Multipeer Connectivity Framework

PowerShell: A Language for the Internet of Things #ATLPUG
PowerShell: A Language for the Internet of Things #ATLPUGPowerShell: A Language for the Internet of Things #ATLPUG
PowerShell: A Language for the Internet of Things #ATLPUGTaylor Riggan
 
Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)Amarjeetsingh Thakur
 
Presentation15 parse xml
Presentation15 parse xmlPresentation15 parse xml
Presentation15 parse xmlAnkit Desai
 
Generating cross platform .NET based azure IoTdevice
Generating cross platform .NET based azure IoTdeviceGenerating cross platform .NET based azure IoTdevice
Generating cross platform .NET based azure IoTdeviceAlon Fliess
 
From Zero to Cloud in 12 Easy Factors
From Zero to Cloud in 12 Easy FactorsFrom Zero to Cloud in 12 Easy Factors
From Zero to Cloud in 12 Easy FactorsEd King
 
Assistive Technology_Research
Assistive Technology_ResearchAssistive Technology_Research
Assistive Technology_ResearchMeng Kry
 
Easy2park - A smarter way to find a parking lot
Easy2park - A smarter way to find a parking lotEasy2park - A smarter way to find a parking lot
Easy2park - A smarter way to find a parking lotDaniele Davoli
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSMohammad Shaker
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsMatteo Manchi
 
4th semester project report
4th semester project report4th semester project report
4th semester project reportAkash Rajguru
 
Mini project final presentation
Mini project final presentationMini project final presentation
Mini project final presentationGianlucaCapozzi1
 
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...DataLeader.io
 
Azure IoT suite - A look behind the curtain (Sam Vanhoutte @AZUG Event)
Azure IoT suite - A look behind the curtain (Sam Vanhoutte @AZUG Event)Azure IoT suite - A look behind the curtain (Sam Vanhoutte @AZUG Event)
Azure IoT suite - A look behind the curtain (Sam Vanhoutte @AZUG Event)Codit
 
Converting Your Mobile App to the Mobile Cloud
Converting Your Mobile App to the Mobile CloudConverting Your Mobile App to the Mobile Cloud
Converting Your Mobile App to the Mobile CloudRoger Brinkley
 
Implementing new WebAPIs
Implementing new WebAPIsImplementing new WebAPIs
Implementing new WebAPIsJulian Viereck
 
Build resource server & client for OCF Cloud (2018.8.30)
Build resource server & client for OCF Cloud (2018.8.30)Build resource server & client for OCF Cloud (2018.8.30)
Build resource server & client for OCF Cloud (2018.8.30)남균 김
 

Similar to 2014.06.26 CocoaHeads - Multipeer Connectivity Framework (20)

PowerShell: A Language for the Internet of Things #ATLPUG
PowerShell: A Language for the Internet of Things #ATLPUGPowerShell: A Language for the Internet of Things #ATLPUG
PowerShell: A Language for the Internet of Things #ATLPUG
 
Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)
 
Presentation15 parse xml
Presentation15 parse xmlPresentation15 parse xml
Presentation15 parse xml
 
Generating cross platform .NET based azure IoTdevice
Generating cross platform .NET based azure IoTdeviceGenerating cross platform .NET based azure IoTdevice
Generating cross platform .NET based azure IoTdevice
 
iOS
iOSiOS
iOS
 
IoT on Raspberry Pi
IoT on Raspberry PiIoT on Raspberry Pi
IoT on Raspberry Pi
 
From Zero to Cloud in 12 Easy Factors
From Zero to Cloud in 12 Easy FactorsFrom Zero to Cloud in 12 Easy Factors
From Zero to Cloud in 12 Easy Factors
 
Assistive Technology_Research
Assistive Technology_ResearchAssistive Technology_Research
Assistive Technology_Research
 
Easy2park - A smarter way to find a parking lot
Easy2park - A smarter way to find a parking lotEasy2park - A smarter way to find a parking lot
Easy2park - A smarter way to find a parking lot
 
04 objective-c session 4
04  objective-c session 404  objective-c session 4
04 objective-c session 4
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
 
4th semester project report
4th semester project report4th semester project report
4th semester project report
 
Mini project final presentation
Mini project final presentationMini project final presentation
Mini project final presentation
 
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
 
Azure IoT suite - A look behind the curtain (Sam Vanhoutte @AZUG Event)
Azure IoT suite - A look behind the curtain (Sam Vanhoutte @AZUG Event)Azure IoT suite - A look behind the curtain (Sam Vanhoutte @AZUG Event)
Azure IoT suite - A look behind the curtain (Sam Vanhoutte @AZUG Event)
 
Converting Your Mobile App to the Mobile Cloud
Converting Your Mobile App to the Mobile CloudConverting Your Mobile App to the Mobile Cloud
Converting Your Mobile App to the Mobile Cloud
 
Implementing New Web
Implementing New WebImplementing New Web
Implementing New Web
 
Implementing new WebAPIs
Implementing new WebAPIsImplementing new WebAPIs
Implementing new WebAPIs
 
Build resource server & client for OCF Cloud (2018.8.30)
Build resource server & client for OCF Cloud (2018.8.30)Build resource server & client for OCF Cloud (2018.8.30)
Build resource server & client for OCF Cloud (2018.8.30)
 

Recently uploaded

Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Niamh verma
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...wyqazy
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPsychicRuben LoveSpells
 
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝soniya singh
 

Recently uploaded (8)

Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
 

2014.06.26 CocoaHeads - Multipeer Connectivity Framework