Giter Site home page Giter Site logo

mkonearbyfilerequest's Introduction

MKONearbyFileRequest

The usual workflow for a user to receive a file from a nearby peer is to ask her to send it to a specific device. MKONearbyFileRequest, however, enables you to request a file and download it from every nearby peer that is ready to share it with you.

Requirements

MKONearbyFileRequest requires the MultipeerConnectivity Framework, hence iOS 7.0 and higher versions are supported.

Installation

Add the MultipeerConnectivity.framework to your target's Linked Frameworks and Libraries section. Drag the MKONearbyFileRequest folder to your project and make sure the following checkboxes are selected:

  • Copy items if needed
  • Add to targets

Objective-C

Import the following header file to the class where you like to use it:

#import "MKONearbyFileRequest.h"

Swift

  1. To import Objective-C files to your Swift project, you rely on an Objective-C bridging header to expose those files to Swift. Xcode offers to create this header file when you add the MKONearbyFileRequest files to your existing Swift app.
    Alternatively, you can create a bridging header yourself by choosing File > New > File > iOS > Source > Header File and name it projectname-bridging-header.h.

  2. In your Objective-C bridging header file, import the following header file:

    #import "MKONearbyFileRequest.h"
  3. Under Build Settings, make sure the Objective-C Bridging Header build setting under Swift Compiler - Code Generation has a path to the header. The path should be relative to your project, similar to the way your Info.plist path is specified in Build Settings. In most cases, you should not need to modify this setting.

Usage

Setup

MKOBundleFileLocator *fileLocator = [MKOBundleFileLocator new];
MKONearbyFileRequest *fileRequest = [[MKONearbyFileRequest alloc] initWithDisplayName:displayName fileLocator:fileLocator];
[fileRequest startRequestListener];

There's currently one implementation of the MKOFilelocator protocol available, which can locate a file in the local bundle. You can simply create your own file locator (e.g. looking up files in your database or file system) by implementing the following methods:

- (BOOL)fileExists:(NSString *)uuid;
- (NSURL *)fileWithUUID:(NSString *)uuid;

Start Request

MKONearbyFileRequestOperation *operation = [fileRequest requestFile:@"image-123456789.jpg" 
  progress:^(MKONearbyFileRequestOperation *operation, float progress) {
    // show progress in UI
  } 
  completion:^(MKONearbyFileRequestOperation *operation, NSURL *url, NSError *error) {
	NSData *data = [[NSFileManager defaultManager] contentsAtPath:[url path]];
    UIImage *image = [UIImage imageWithData:data];
  }
];

Cancel Request

[operation cancel];

License

MKNearbyFileRequest is available under the MIT license. See the LICENSE file for more info.

Recent Changes

The release notes can be found here.

mkonearbyfilerequest's People

Contributors

mkoehnke avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

mkonearbyfilerequest's Issues

Increase Discovery Timeout

Sometimes a peer gets disconnected (manually) when accepting an invitation and stopping the advertising.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.