A very simple wrapper for the iOS7 Multipeer Connectivity framework.
MultiMagic is available through CocoaPods, to install
it simply add the following line to your Podfile:
I haven't gotten round to submitting this to Cocoapods yet, so for now you can install this by adding the following code to your Podfile:
pod 'MultiMagic', :git => "[email protected]:ZackMcBride/MultiMagic.git", :tag => 'v0.0.3'
and then running pod install
from your project directory.
Getting started is easy. Just write
[MultiMagic.manager startSessionWithName:[UIDevice currentDevice].name
visible:YES];
- Set your current view controller as the browser delegate
MultiMagic.manager.browser.delegate = self;
- Present the browser
[self presentViewController:MultiMagic.manager.browser
animated:YES
completion:nil];
This will enable the default iOS modal viewController for connecting with peers.
- Implement this block (it's probably good to do this at the same time that you start the session)
MultiMagic.manager.onSessionDidChangeState = ^(MMState *state){
// Do some good stuff here...
};
This will fire whenever something changes in your session
Use these blocks to interact with all that multipeer goodness
@property (nonatomic, copy) void (^onSessionDidReceiveData)(MMData *data);
This will get called whenever data is received from another peer. You receive an MMData instance which holds the message.
@property (nonatomic, copy) void (^onSessionDidReceiveStream)(MMStream *stream);
This will get called when a nearby peer opens a stream to your device. The MMStream object you receive contains an NSInputStream.
@property (nonatomic, copy) void (^onSessionDidStartReceivingResource)(MMResource *resource);
Indicates that you have begun receiving a resource from another peer. This instance of MMResource holds an NSProgress object.
@property (nonatomic, copy) void (^onSessionDidFinishReceivingResource)(MMResource *resource);
Indicates that the stream you have been receiving just finished. It contains an NSURL object pointing to the brand new local file stored on your device.
Simple data
[MultiMagic.manager.session sendData:(NSData *)data
toPeers:(NSArray *)peerIDs
withMode:(MCSessionSendDataMode)mode
error:(NSError **)error;
Files
[MultiMagic.manager.session sendResourceAtURL:(NSURL *)resourceURL
withName:(NSString *)resourceName
toPeer:(MCPeerID *)peerID
withCompletionHandler:(void(^)(NSError *error))completionHandler;
Streams
[MultiMagic.manager.session startStreamWithName:(NSString *)streamName
toPeer:(MCPeerID *)peerID
error:(NSError **)error;
Hopefully you get the idea. Have fun!
Zack McBride, [email protected]
MultiMagic is available under the MIT license. See the LICENSE file for more info.