├── README.md
└── MCSession
├── MCSession.xcodeproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcuserdata
│ │ ├── liushuo.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
│ │ └── qianfeng.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
├── xcuserdata
│ ├── qianfeng.xcuserdatad
│ │ ├── xcdebugger
│ │ │ └── Breakpoints_v2.xcbkptlist
│ │ └── xcschemes
│ │ │ ├── xcschememanagement.plist
│ │ │ └── MCSession.xcscheme
│ └── liushuo.xcuserdatad
│ │ └── xcschemes
│ │ ├── xcschememanagement.plist
│ │ └── MCSession.xcscheme
└── project.pbxproj
├── MCSession
├── ViewController.h
├── AppDelegate.h
├── main.m
├── Images.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── Info.plist
├── Base.lproj
│ ├── Main.storyboard
│ └── LaunchScreen.xib
├── AppDelegate.m
└── ViewController.m
└── MCSessionTests
├── Info.plist
└── MCSessionTests.m
/README.md:
--------------------------------------------------------------------------------
1 | # MultipeerConnectivityDemo
2 | 《iOS被遗忘的近距离通讯利器-MultipeerConnectivity》文中所述demo。文章链接:http://www.jianshu.com/p/662dd49d82b6
3 |
--------------------------------------------------------------------------------
/MCSession/MCSession.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/MCSession/MCSession.xcodeproj/project.xcworkspace/xcuserdata/liushuo.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LSure/MultipeerConnectivityDemo/HEAD/MCSession/MCSession.xcodeproj/project.xcworkspace/xcuserdata/liushuo.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/MCSession/MCSession.xcodeproj/project.xcworkspace/xcuserdata/qianfeng.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LSure/MultipeerConnectivityDemo/HEAD/MCSession/MCSession.xcodeproj/project.xcworkspace/xcuserdata/qianfeng.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/MCSession/MCSession/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // MCSession
4 | //
5 | // Created by 刘硕-卖报的小画家 on 15-12-28.
6 | // Copyright (c) 2015年 刘硕. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/MCSession/MCSession/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // MCSession
4 | //
5 | // Created by 刘硕-卖报的小画家 on 15-12-28.
6 | // Copyright (c) 2015年 刘硕. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/MCSession/MCSession/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // MCSession
4 | //
5 | // Created by 刘硕-卖报的小画家 on 15-12-28.
6 | // Copyright (c) 2015年 刘硕. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/MCSession/MCSession.xcodeproj/xcuserdata/qianfeng.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/MCSession/MCSession.xcodeproj/xcuserdata/liushuo.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | MCSession.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | BC42CE7B1C31197C004C6091
16 |
17 | primary
18 |
19 |
20 | BC42CE941C31197C004C6091
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/MCSession/MCSession.xcodeproj/xcuserdata/qianfeng.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | MCSession.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | BC42CE7B1C31197C004C6091
16 |
17 | primary
18 |
19 |
20 | BC42CE941C31197C004C6091
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/MCSession/MCSession/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | }
33 | ],
34 | "info" : {
35 | "version" : 1,
36 | "author" : "xcode"
37 | }
38 | }
--------------------------------------------------------------------------------
/MCSession/MCSessionTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.Sure.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/MCSession/MCSessionTests/MCSessionTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // MCSessionTests.m
3 | // MCSessionTests
4 | //
5 | // Created by 刘硕-卖报的小画家 on 15-12-28.
6 | // Copyright (c) 2015年 刘硕. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface MCSessionTests : XCTestCase
13 |
14 | @end
15 |
16 | @implementation MCSessionTests
17 |
18 | - (void)setUp {
19 | [super setUp];
20 | // Put setup code here. This method is called before the invocation of each test method in the class.
21 | }
22 |
23 | - (void)tearDown {
24 | // Put teardown code here. This method is called after the invocation of each test method in the class.
25 | [super tearDown];
26 | }
27 |
28 | - (void)testExample {
29 | // This is an example of a functional test case.
30 | XCTAssert(YES, @"Pass");
31 | }
32 |
33 | - (void)testPerformanceExample {
34 | // This is an example of a performance test case.
35 | [self measureBlock:^{
36 | // Put the code you want to measure the time of here.
37 | }];
38 | }
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/MCSession/MCSession/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/MCSession/MCSession/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/MCSession/MCSession/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // MCSession
4 | //
5 | // Created by 刘硕-卖报的小画家 on 15-12-28.
6 | // Copyright (c) 2015年 刘硕. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 | - (void)applicationWillResignActive:(UIApplication *)application {
24 | // 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.
25 | // 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.
26 | }
27 |
28 | - (void)applicationDidEnterBackground:(UIApplication *)application {
29 | // 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.
30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
31 | }
32 |
33 | - (void)applicationWillEnterForeground:(UIApplication *)application {
34 | // 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.
35 | }
36 |
37 | - (void)applicationDidBecomeActive:(UIApplication *)application {
38 | // 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.
39 | }
40 |
41 | - (void)applicationWillTerminate:(UIApplication *)application {
42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 | }
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/MCSession/MCSession/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/MCSession/MCSession.xcodeproj/xcuserdata/liushuo.xcuserdatad/xcschemes/MCSession.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
53 |
54 |
64 |
66 |
72 |
73 |
74 |
75 |
76 |
77 |
83 |
85 |
91 |
92 |
93 |
94 |
96 |
97 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/MCSession/MCSession.xcodeproj/xcuserdata/qianfeng.xcuserdatad/xcschemes/MCSession.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
38 |
39 |
44 |
45 |
47 |
53 |
54 |
55 |
56 |
57 |
63 |
64 |
65 |
66 |
75 |
76 |
82 |
83 |
84 |
85 |
86 |
87 |
93 |
94 |
100 |
101 |
102 |
103 |
105 |
106 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/MCSession/MCSession/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // MCSession
4 | //
5 | // Created by 刘硕-卖报的小画家 on 15-12-28.
6 | // Copyright (c) 2015年 刘硕. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 | #define WIDTH [UIScreen mainScreen].bounds.size.width
11 | #define HEIGHT [UIScreen mainScreen].bounds.size.height
12 | //MultipeerConnectivity,这个框架可以通过,同一Wifi,蓝牙,来近距离传输数据。
13 | #import
14 | @interface ViewController ()
15 | /**
16 | * 表示为一个用户
17 | */
18 | @property (nonatomic,strong)MCPeerID * peerID;
19 | /**
20 | * 启用和管理Multipeer连接会话中的所有人之间的沟通。 通过Sesion,给别人发送数据。类似于Scoket
21 | */
22 | @property (nonatomic,strong)MCSession * session;
23 | /**
24 | * 可以接收,并处理用户请求连接的响应。没有回调,会弹出默认的提示框,并处理连接。
25 | */
26 | @property (nonatomic,strong)MCAdvertiserAssistant * advertiser;
27 | /**
28 | * 用于搜索附近的用户,并可以对搜索到的用户发出邀请加入某个会话中。
29 | */
30 | @property (nonatomic,strong)MCNearbyServiceBrowser * brower;
31 | /**
32 | * 附近用户列表
33 | */
34 | @property (nonatomic,strong)MCBrowserViewController * browserViewController;
35 | /**
36 | * 存储连接
37 | */
38 | @property (nonatomic,strong)NSMutableArray * sessionArray;
39 | /**
40 | * 会话列表
41 | */
42 | @property (nonatomic,strong)UITableView * tableView;
43 | /**
44 | * 数据源
45 | */
46 | @property (nonatomic,strong)NSMutableArray * dataArray;
47 | /**
48 | * 输入框
49 | */
50 | @property (nonatomic,strong)UITextField * chatField;
51 |
52 | @end
53 |
54 | @implementation ViewController
55 |
56 | - (void)viewDidLoad {
57 | [super viewDidLoad];
58 | _dataArray = [NSMutableArray arrayWithCapacity:0];
59 | _sessionArray = [NSMutableArray arrayWithCapacity:0];
60 | /**
61 | * UI布局
62 | */
63 | [self createUI];
64 | /**
65 | * 连接设置
66 | */
67 | [self createMC];
68 |
69 | // Do any additional setup after loading the view, typically from a nib.
70 | }
71 | /**
72 | * UI布局
73 | */
74 | - (void)createUI{
75 | /**
76 | * 会话列表
77 | */
78 | _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, WIDTH, HEIGHT - 400) style:UITableViewStylePlain];
79 | _tableView.dataSource = self;
80 | _tableView.delegate = self;
81 | [self.view addSubview:_tableView];
82 | [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"ID"];
83 |
84 | _chatField = [[UITextField alloc]initWithFrame:CGRectMake(0, HEIGHT - 360, WIDTH, 40)];
85 | _chatField.borderStyle = UITextBorderStyleBezel;
86 | _chatField.returnKeyType = UIReturnKeySend;
87 | _chatField.delegate = self;
88 | [self.view addSubview:_chatField];
89 | }
90 | #pragma mark TableViewDelegate
91 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
92 | return _dataArray.count;
93 | }
94 | - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
95 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ID" forIndexPath:indexPath];
96 | cell.textLabel.text = _dataArray[indexPath.row];
97 | return cell;
98 | }
99 | #pragma mark TextFieldDelegate
100 | - (BOOL)textFieldShouldReturn:(UITextField *)textField{
101 | if (textField.text.length > 0) {
102 | /**
103 | * 两种类型
104 | MCSessionSendDataUnreliable 类似于UDP连接方式
105 | MCSessionSendDataReliable 类似于TCP连接方式
106 | */
107 | [_session sendData:[textField.text dataUsingEncoding:NSUTF8StringEncoding] toPeers:_session.connectedPeers withMode:MCSessionSendDataUnreliable error:nil];
108 | //UI操作
109 | [_dataArray addObject:textField.text];
110 | NSIndexPath * indexPath = [NSIndexPath indexPathForRow:_dataArray.count - 1 inSection:0];
111 | [_tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
112 | [_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
113 | }
114 | return YES;
115 | }
116 | /**
117 | * 连接设置
118 | */
119 | - (void)createMC{
120 | //获取设备名称
121 | NSString * name = [UIDevice currentDevice].name;
122 | //用户
123 | _peerID = [[MCPeerID alloc]initWithDisplayName:name];
124 | //为用户建立连接
125 | _session = [[MCSession alloc]initWithPeer:_peerID];
126 | //设置代理
127 | _session.delegate = self;
128 | //设置广播服务(发送方)
129 | _advertiser = [[MCAdvertiserAssistant alloc]initWithServiceType:@"type" discoveryInfo:nil session:_session];
130 | //开始广播
131 | [_advertiser start];
132 | //设置发现服务(接收方)
133 | _brower = [[MCNearbyServiceBrowser alloc]initWithPeer:_peerID serviceType:@"type"];
134 | //设置代理
135 | _brower.delegate = self;
136 | [_brower startBrowsingForPeers];
137 | }
138 | #pragma MC相关代理方法
139 | /**
140 | * 发现附近用户
141 | *
142 | * @param browser 搜索附近用户
143 | * @param peerID 附近用户
144 | * @param info 详情
145 | */
146 | - (void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary *)info{
147 | NSLog(@"发现附近用户%@",peerID.displayName);
148 | if (_browserViewController == nil) {
149 | _browserViewController = [[MCBrowserViewController alloc]initWithServiceType:@"type" session:_session];
150 | _browserViewController.delegate = self;
151 | /**
152 | * 跳转发现界面
153 | */
154 | [self presentViewController:_browserViewController animated:YES completion:nil];
155 | }
156 | }
157 | /**
158 | * 附近某个用户消失了
159 | *
160 | * @param browser 搜索附近用户
161 | * @param peerID 用户
162 | */
163 | - (void)browser:(MCNearbyServiceBrowser *)browser lostPeer:(MCPeerID *)peerID{
164 | NSLog(@"附近用户%@离开了",peerID.displayName);
165 | }
166 | #pragma mark BrowserViewController附近用户列表视图相关代理方法
167 | /**
168 | * 选取相应用户
169 | *
170 | * @param browserViewController 用户列表
171 | */
172 | - (void)browserViewControllerDidFinish:(MCBrowserViewController *)browserViewController{
173 | [self dismissViewControllerAnimated:YES completion:nil];
174 | _browserViewController = nil;
175 | //关闭广播服务,停止其他人发现
176 | [_advertiser stop];
177 | }
178 | /**
179 | * 用户列表关闭
180 | *
181 | * @param browserViewController 用户列表
182 | */
183 | - (void)browserViewControllerWasCancelled:(MCBrowserViewController *)browserViewController{
184 | [self dismissViewControllerAnimated:YES completion:nil];
185 | _browserViewController = nil;
186 | [_advertiser stop];
187 | }
188 | #pragma mark MCSession代理方法
189 | /**
190 | * 当检测到连接状态发生改变后进行存储
191 | *
192 | * @param session MC流
193 | * @param peerID 用户
194 | * @param state 连接状态
195 | */
196 | - (void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state{
197 | //判断如果连接
198 | if (state == MCSessionStateConnected) {
199 | //保存这个连接
200 | if (![_sessionArray containsObject:session]) {
201 | //如果不存在 保存
202 | [_sessionArray addObject:session];
203 | }
204 | }
205 | }
206 | /**
207 | * 接收到消息
208 | *
209 | * @param session MC流
210 | * @param data 传入的二进制数据
211 | * @param peerID 用户
212 | */
213 | - (void)session:(MCSession *)session didReceiveData:(NSData *)data fromPeer:(MCPeerID *)peerID{
214 | NSString * message = [NSString stringWithFormat:@"%@:%@",peerID.displayName,[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]];
215 | dispatch_async(dispatch_get_main_queue(), ^{
216 | [_dataArray addObject:message];
217 | NSIndexPath * indexPath = [NSIndexPath indexPathForRow:_dataArray.count - 1 inSection:0];
218 | [_tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
219 | [_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
220 | });
221 | }
222 | /**
223 | * 接收数据流
224 | *
225 | * @param session MC流
226 | * @param stream 数据流
227 | * @param streamName 数据流名称(标示)
228 | * @param peerID 用户
229 | */
230 | - (void)session:(MCSession *)session didReceiveStream:(NSInputStream *)stream withName:(NSString *)streamName fromPeer:(MCPeerID *)peerID{
231 |
232 | }
233 | /**
234 | * 开始接收资源
235 | *
236 | * @param session MC流
237 | * @param resourceName 资源名称
238 | * @param peerID 用户
239 | * @param progress 进度
240 | */
241 | - (void)session:(MCSession *)session didStartReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID withProgress:(NSProgress *)progress{
242 |
243 | }
244 | /**
245 | * 资源接收结束
246 | *
247 | * @param session MC流
248 | * @param resourceName 资源名称
249 | * @param peerID 用户
250 | * @param localURL 本地资源
251 | * @param error 报错信息
252 | */
253 | - (void)session:(MCSession *)session didFinishReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID atURL:(NSURL *)localURL withError:(NSError *)error{
254 |
255 | }
256 | - (void)didReceiveMemoryWarning {
257 | [super didReceiveMemoryWarning];
258 | // Dispose of any resources that can be recreated.
259 | }
260 |
261 | @end
262 |
--------------------------------------------------------------------------------
/MCSession/MCSession.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | BC42CE821C31197C004C6091 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = BC42CE811C31197C004C6091 /* main.m */; };
11 | BC42CE851C31197C004C6091 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = BC42CE841C31197C004C6091 /* AppDelegate.m */; };
12 | BC42CE881C31197C004C6091 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BC42CE871C31197C004C6091 /* ViewController.m */; };
13 | BC42CE8B1C31197C004C6091 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BC42CE891C31197C004C6091 /* Main.storyboard */; };
14 | BC42CE8D1C31197C004C6091 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BC42CE8C1C31197C004C6091 /* Images.xcassets */; };
15 | BC42CE901C31197C004C6091 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = BC42CE8E1C31197C004C6091 /* LaunchScreen.xib */; };
16 | BC42CE9C1C31197C004C6091 /* MCSessionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BC42CE9B1C31197C004C6091 /* MCSessionTests.m */; };
17 | /* End PBXBuildFile section */
18 |
19 | /* Begin PBXContainerItemProxy section */
20 | BC42CE961C31197C004C6091 /* PBXContainerItemProxy */ = {
21 | isa = PBXContainerItemProxy;
22 | containerPortal = BC42CE741C31197C004C6091 /* Project object */;
23 | proxyType = 1;
24 | remoteGlobalIDString = BC42CE7B1C31197C004C6091;
25 | remoteInfo = MCSession;
26 | };
27 | /* End PBXContainerItemProxy section */
28 |
29 | /* Begin PBXFileReference section */
30 | BC42CE7C1C31197C004C6091 /* MCSession.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MCSession.app; sourceTree = BUILT_PRODUCTS_DIR; };
31 | BC42CE801C31197C004C6091 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
32 | BC42CE811C31197C004C6091 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
33 | BC42CE831C31197C004C6091 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
34 | BC42CE841C31197C004C6091 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
35 | BC42CE861C31197C004C6091 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; };
36 | BC42CE871C31197C004C6091 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; };
37 | BC42CE8A1C31197C004C6091 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
38 | BC42CE8C1C31197C004C6091 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; };
39 | BC42CE8F1C31197C004C6091 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; };
40 | BC42CE951C31197C004C6091 /* MCSessionTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MCSessionTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
41 | BC42CE9A1C31197C004C6091 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
42 | BC42CE9B1C31197C004C6091 /* MCSessionTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MCSessionTests.m; sourceTree = ""; };
43 | /* End PBXFileReference section */
44 |
45 | /* Begin PBXFrameworksBuildPhase section */
46 | BC42CE791C31197C004C6091 /* Frameworks */ = {
47 | isa = PBXFrameworksBuildPhase;
48 | buildActionMask = 2147483647;
49 | files = (
50 | );
51 | runOnlyForDeploymentPostprocessing = 0;
52 | };
53 | BC42CE921C31197C004C6091 /* Frameworks */ = {
54 | isa = PBXFrameworksBuildPhase;
55 | buildActionMask = 2147483647;
56 | files = (
57 | );
58 | runOnlyForDeploymentPostprocessing = 0;
59 | };
60 | /* End PBXFrameworksBuildPhase section */
61 |
62 | /* Begin PBXGroup section */
63 | BC42CE731C31197C004C6091 = {
64 | isa = PBXGroup;
65 | children = (
66 | BC42CE7E1C31197C004C6091 /* MCSession */,
67 | BC42CE981C31197C004C6091 /* MCSessionTests */,
68 | BC42CE7D1C31197C004C6091 /* Products */,
69 | );
70 | sourceTree = "";
71 | };
72 | BC42CE7D1C31197C004C6091 /* Products */ = {
73 | isa = PBXGroup;
74 | children = (
75 | BC42CE7C1C31197C004C6091 /* MCSession.app */,
76 | BC42CE951C31197C004C6091 /* MCSessionTests.xctest */,
77 | );
78 | name = Products;
79 | sourceTree = "";
80 | };
81 | BC42CE7E1C31197C004C6091 /* MCSession */ = {
82 | isa = PBXGroup;
83 | children = (
84 | BC42CE831C31197C004C6091 /* AppDelegate.h */,
85 | BC42CE841C31197C004C6091 /* AppDelegate.m */,
86 | BC42CE861C31197C004C6091 /* ViewController.h */,
87 | BC42CE871C31197C004C6091 /* ViewController.m */,
88 | BC42CE891C31197C004C6091 /* Main.storyboard */,
89 | BC42CE8C1C31197C004C6091 /* Images.xcassets */,
90 | BC42CE8E1C31197C004C6091 /* LaunchScreen.xib */,
91 | BC42CE7F1C31197C004C6091 /* Supporting Files */,
92 | );
93 | path = MCSession;
94 | sourceTree = "";
95 | };
96 | BC42CE7F1C31197C004C6091 /* Supporting Files */ = {
97 | isa = PBXGroup;
98 | children = (
99 | BC42CE801C31197C004C6091 /* Info.plist */,
100 | BC42CE811C31197C004C6091 /* main.m */,
101 | );
102 | name = "Supporting Files";
103 | sourceTree = "";
104 | };
105 | BC42CE981C31197C004C6091 /* MCSessionTests */ = {
106 | isa = PBXGroup;
107 | children = (
108 | BC42CE9B1C31197C004C6091 /* MCSessionTests.m */,
109 | BC42CE991C31197C004C6091 /* Supporting Files */,
110 | );
111 | path = MCSessionTests;
112 | sourceTree = "";
113 | };
114 | BC42CE991C31197C004C6091 /* Supporting Files */ = {
115 | isa = PBXGroup;
116 | children = (
117 | BC42CE9A1C31197C004C6091 /* Info.plist */,
118 | );
119 | name = "Supporting Files";
120 | sourceTree = "";
121 | };
122 | /* End PBXGroup section */
123 |
124 | /* Begin PBXNativeTarget section */
125 | BC42CE7B1C31197C004C6091 /* MCSession */ = {
126 | isa = PBXNativeTarget;
127 | buildConfigurationList = BC42CE9F1C31197C004C6091 /* Build configuration list for PBXNativeTarget "MCSession" */;
128 | buildPhases = (
129 | BC42CE781C31197C004C6091 /* Sources */,
130 | BC42CE791C31197C004C6091 /* Frameworks */,
131 | BC42CE7A1C31197C004C6091 /* Resources */,
132 | );
133 | buildRules = (
134 | );
135 | dependencies = (
136 | );
137 | name = MCSession;
138 | productName = MCSession;
139 | productReference = BC42CE7C1C31197C004C6091 /* MCSession.app */;
140 | productType = "com.apple.product-type.application";
141 | };
142 | BC42CE941C31197C004C6091 /* MCSessionTests */ = {
143 | isa = PBXNativeTarget;
144 | buildConfigurationList = BC42CEA21C31197C004C6091 /* Build configuration list for PBXNativeTarget "MCSessionTests" */;
145 | buildPhases = (
146 | BC42CE911C31197C004C6091 /* Sources */,
147 | BC42CE921C31197C004C6091 /* Frameworks */,
148 | BC42CE931C31197C004C6091 /* Resources */,
149 | );
150 | buildRules = (
151 | );
152 | dependencies = (
153 | BC42CE971C31197C004C6091 /* PBXTargetDependency */,
154 | );
155 | name = MCSessionTests;
156 | productName = MCSessionTests;
157 | productReference = BC42CE951C31197C004C6091 /* MCSessionTests.xctest */;
158 | productType = "com.apple.product-type.bundle.unit-test";
159 | };
160 | /* End PBXNativeTarget section */
161 |
162 | /* Begin PBXProject section */
163 | BC42CE741C31197C004C6091 /* Project object */ = {
164 | isa = PBXProject;
165 | attributes = {
166 | LastUpgradeCheck = 0610;
167 | ORGANIZATIONNAME = "北京千锋互联科技有限公司";
168 | TargetAttributes = {
169 | BC42CE7B1C31197C004C6091 = {
170 | CreatedOnToolsVersion = 6.1;
171 | DevelopmentTeam = UH3CV2MYJP;
172 | };
173 | BC42CE941C31197C004C6091 = {
174 | CreatedOnToolsVersion = 6.1;
175 | TestTargetID = BC42CE7B1C31197C004C6091;
176 | };
177 | };
178 | };
179 | buildConfigurationList = BC42CE771C31197C004C6091 /* Build configuration list for PBXProject "MCSession" */;
180 | compatibilityVersion = "Xcode 3.2";
181 | developmentRegion = English;
182 | hasScannedForEncodings = 0;
183 | knownRegions = (
184 | en,
185 | Base,
186 | );
187 | mainGroup = BC42CE731C31197C004C6091;
188 | productRefGroup = BC42CE7D1C31197C004C6091 /* Products */;
189 | projectDirPath = "";
190 | projectRoot = "";
191 | targets = (
192 | BC42CE7B1C31197C004C6091 /* MCSession */,
193 | BC42CE941C31197C004C6091 /* MCSessionTests */,
194 | );
195 | };
196 | /* End PBXProject section */
197 |
198 | /* Begin PBXResourcesBuildPhase section */
199 | BC42CE7A1C31197C004C6091 /* Resources */ = {
200 | isa = PBXResourcesBuildPhase;
201 | buildActionMask = 2147483647;
202 | files = (
203 | BC42CE8B1C31197C004C6091 /* Main.storyboard in Resources */,
204 | BC42CE901C31197C004C6091 /* LaunchScreen.xib in Resources */,
205 | BC42CE8D1C31197C004C6091 /* Images.xcassets in Resources */,
206 | );
207 | runOnlyForDeploymentPostprocessing = 0;
208 | };
209 | BC42CE931C31197C004C6091 /* Resources */ = {
210 | isa = PBXResourcesBuildPhase;
211 | buildActionMask = 2147483647;
212 | files = (
213 | );
214 | runOnlyForDeploymentPostprocessing = 0;
215 | };
216 | /* End PBXResourcesBuildPhase section */
217 |
218 | /* Begin PBXSourcesBuildPhase section */
219 | BC42CE781C31197C004C6091 /* Sources */ = {
220 | isa = PBXSourcesBuildPhase;
221 | buildActionMask = 2147483647;
222 | files = (
223 | BC42CE881C31197C004C6091 /* ViewController.m in Sources */,
224 | BC42CE851C31197C004C6091 /* AppDelegate.m in Sources */,
225 | BC42CE821C31197C004C6091 /* main.m in Sources */,
226 | );
227 | runOnlyForDeploymentPostprocessing = 0;
228 | };
229 | BC42CE911C31197C004C6091 /* Sources */ = {
230 | isa = PBXSourcesBuildPhase;
231 | buildActionMask = 2147483647;
232 | files = (
233 | BC42CE9C1C31197C004C6091 /* MCSessionTests.m in Sources */,
234 | );
235 | runOnlyForDeploymentPostprocessing = 0;
236 | };
237 | /* End PBXSourcesBuildPhase section */
238 |
239 | /* Begin PBXTargetDependency section */
240 | BC42CE971C31197C004C6091 /* PBXTargetDependency */ = {
241 | isa = PBXTargetDependency;
242 | target = BC42CE7B1C31197C004C6091 /* MCSession */;
243 | targetProxy = BC42CE961C31197C004C6091 /* PBXContainerItemProxy */;
244 | };
245 | /* End PBXTargetDependency section */
246 |
247 | /* Begin PBXVariantGroup section */
248 | BC42CE891C31197C004C6091 /* Main.storyboard */ = {
249 | isa = PBXVariantGroup;
250 | children = (
251 | BC42CE8A1C31197C004C6091 /* Base */,
252 | );
253 | name = Main.storyboard;
254 | sourceTree = "";
255 | };
256 | BC42CE8E1C31197C004C6091 /* LaunchScreen.xib */ = {
257 | isa = PBXVariantGroup;
258 | children = (
259 | BC42CE8F1C31197C004C6091 /* Base */,
260 | );
261 | name = LaunchScreen.xib;
262 | sourceTree = "";
263 | };
264 | /* End PBXVariantGroup section */
265 |
266 | /* Begin XCBuildConfiguration section */
267 | BC42CE9D1C31197C004C6091 /* Debug */ = {
268 | isa = XCBuildConfiguration;
269 | buildSettings = {
270 | ALWAYS_SEARCH_USER_PATHS = NO;
271 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
272 | CLANG_CXX_LIBRARY = "libc++";
273 | CLANG_ENABLE_MODULES = YES;
274 | CLANG_ENABLE_OBJC_ARC = YES;
275 | CLANG_WARN_BOOL_CONVERSION = YES;
276 | CLANG_WARN_CONSTANT_CONVERSION = YES;
277 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
278 | CLANG_WARN_EMPTY_BODY = YES;
279 | CLANG_WARN_ENUM_CONVERSION = YES;
280 | CLANG_WARN_INT_CONVERSION = YES;
281 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
282 | CLANG_WARN_UNREACHABLE_CODE = YES;
283 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
284 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
285 | COPY_PHASE_STRIP = NO;
286 | ENABLE_STRICT_OBJC_MSGSEND = YES;
287 | GCC_C_LANGUAGE_STANDARD = gnu99;
288 | GCC_DYNAMIC_NO_PIC = NO;
289 | GCC_OPTIMIZATION_LEVEL = 0;
290 | GCC_PREPROCESSOR_DEFINITIONS = (
291 | "DEBUG=1",
292 | "$(inherited)",
293 | );
294 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
295 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
296 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
297 | GCC_WARN_UNDECLARED_SELECTOR = YES;
298 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
299 | GCC_WARN_UNUSED_FUNCTION = YES;
300 | GCC_WARN_UNUSED_VARIABLE = YES;
301 | IPHONEOS_DEPLOYMENT_TARGET = 8.1;
302 | MTL_ENABLE_DEBUG_INFO = YES;
303 | ONLY_ACTIVE_ARCH = YES;
304 | SDKROOT = iphoneos;
305 | };
306 | name = Debug;
307 | };
308 | BC42CE9E1C31197C004C6091 /* Release */ = {
309 | isa = XCBuildConfiguration;
310 | buildSettings = {
311 | ALWAYS_SEARCH_USER_PATHS = NO;
312 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
313 | CLANG_CXX_LIBRARY = "libc++";
314 | CLANG_ENABLE_MODULES = YES;
315 | CLANG_ENABLE_OBJC_ARC = YES;
316 | CLANG_WARN_BOOL_CONVERSION = YES;
317 | CLANG_WARN_CONSTANT_CONVERSION = YES;
318 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
319 | CLANG_WARN_EMPTY_BODY = YES;
320 | CLANG_WARN_ENUM_CONVERSION = YES;
321 | CLANG_WARN_INT_CONVERSION = YES;
322 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
323 | CLANG_WARN_UNREACHABLE_CODE = YES;
324 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
325 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
326 | COPY_PHASE_STRIP = YES;
327 | ENABLE_NS_ASSERTIONS = NO;
328 | ENABLE_STRICT_OBJC_MSGSEND = YES;
329 | GCC_C_LANGUAGE_STANDARD = gnu99;
330 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
331 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
332 | GCC_WARN_UNDECLARED_SELECTOR = YES;
333 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
334 | GCC_WARN_UNUSED_FUNCTION = YES;
335 | GCC_WARN_UNUSED_VARIABLE = YES;
336 | IPHONEOS_DEPLOYMENT_TARGET = 8.1;
337 | MTL_ENABLE_DEBUG_INFO = NO;
338 | SDKROOT = iphoneos;
339 | VALIDATE_PRODUCT = YES;
340 | };
341 | name = Release;
342 | };
343 | BC42CEA01C31197C004C6091 /* Debug */ = {
344 | isa = XCBuildConfiguration;
345 | buildSettings = {
346 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
347 | DEVELOPMENT_TEAM = UH3CV2MYJP;
348 | INFOPLIST_FILE = MCSession/Info.plist;
349 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
350 | PRODUCT_BUNDLE_IDENTIFIER = com.sure.MCSession;
351 | PRODUCT_NAME = "$(TARGET_NAME)";
352 | };
353 | name = Debug;
354 | };
355 | BC42CEA11C31197C004C6091 /* Release */ = {
356 | isa = XCBuildConfiguration;
357 | buildSettings = {
358 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
359 | DEVELOPMENT_TEAM = UH3CV2MYJP;
360 | INFOPLIST_FILE = MCSession/Info.plist;
361 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
362 | PRODUCT_BUNDLE_IDENTIFIER = com.sure.MCSession;
363 | PRODUCT_NAME = "$(TARGET_NAME)";
364 | };
365 | name = Release;
366 | };
367 | BC42CEA31C31197C004C6091 /* Debug */ = {
368 | isa = XCBuildConfiguration;
369 | buildSettings = {
370 | BUNDLE_LOADER = "$(TEST_HOST)";
371 | FRAMEWORK_SEARCH_PATHS = (
372 | "$(SDKROOT)/Developer/Library/Frameworks",
373 | "$(inherited)",
374 | );
375 | GCC_PREPROCESSOR_DEFINITIONS = (
376 | "DEBUG=1",
377 | "$(inherited)",
378 | );
379 | INFOPLIST_FILE = MCSessionTests/Info.plist;
380 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
381 | PRODUCT_NAME = "$(TARGET_NAME)";
382 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MCSession.app/MCSession";
383 | };
384 | name = Debug;
385 | };
386 | BC42CEA41C31197C004C6091 /* Release */ = {
387 | isa = XCBuildConfiguration;
388 | buildSettings = {
389 | BUNDLE_LOADER = "$(TEST_HOST)";
390 | FRAMEWORK_SEARCH_PATHS = (
391 | "$(SDKROOT)/Developer/Library/Frameworks",
392 | "$(inherited)",
393 | );
394 | INFOPLIST_FILE = MCSessionTests/Info.plist;
395 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
396 | PRODUCT_NAME = "$(TARGET_NAME)";
397 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MCSession.app/MCSession";
398 | };
399 | name = Release;
400 | };
401 | /* End XCBuildConfiguration section */
402 |
403 | /* Begin XCConfigurationList section */
404 | BC42CE771C31197C004C6091 /* Build configuration list for PBXProject "MCSession" */ = {
405 | isa = XCConfigurationList;
406 | buildConfigurations = (
407 | BC42CE9D1C31197C004C6091 /* Debug */,
408 | BC42CE9E1C31197C004C6091 /* Release */,
409 | );
410 | defaultConfigurationIsVisible = 0;
411 | defaultConfigurationName = Release;
412 | };
413 | BC42CE9F1C31197C004C6091 /* Build configuration list for PBXNativeTarget "MCSession" */ = {
414 | isa = XCConfigurationList;
415 | buildConfigurations = (
416 | BC42CEA01C31197C004C6091 /* Debug */,
417 | BC42CEA11C31197C004C6091 /* Release */,
418 | );
419 | defaultConfigurationIsVisible = 0;
420 | defaultConfigurationName = Release;
421 | };
422 | BC42CEA21C31197C004C6091 /* Build configuration list for PBXNativeTarget "MCSessionTests" */ = {
423 | isa = XCConfigurationList;
424 | buildConfigurations = (
425 | BC42CEA31C31197C004C6091 /* Debug */,
426 | BC42CEA41C31197C004C6091 /* Release */,
427 | );
428 | defaultConfigurationIsVisible = 0;
429 | defaultConfigurationName = Release;
430 | };
431 | /* End XCConfigurationList section */
432 | };
433 | rootObject = BC42CE741C31197C004C6091 /* Project object */;
434 | }
435 |
--------------------------------------------------------------------------------