Translate

Monday, 6 April 2015

iOS – File Sharing Using WiFi

Objective: The main objective of this post is to describe how to share file between two apple devices using WiFi. In following demo I have described how to connect two devices using WiFi and then share large size image file by dividing it in data chunks and save shared file in camera roll of other device.
Note : To connect devices and share file application must be installed in both devices.
* Turn Off bluetooth while WiFi sharing, as it will interfere WiFi.
  • iOS – File Sharing Using WiFi
Step 1: Create new XCode project name it as FileShareDemo. It contains one UIViewController Main.storyboard file.
Step 2: Add two UIButton in UIVIewController and set title “Connect” and “Share” respectively in both UIButton.
Step 3: Add MultipeerConnectivity framework in your project. Also add .png file which you want to share.
Step 4: In ViewController.h file you have to import MultipeerConnectivity framework, set delegate and declare property as below.
Step 5: Initialize both NSMutableArray object in viewDidLoad method.
Step 6: Initialize MCSession object, MCBrowserViewController object, and MCPeerID object in setUpMultipeer method.
Also implement below methods in your ViewController.m file.
Step 6: Call setUpMultipeer and showBrowserVC methods from connect button action method.
Step 7: Implement MCBrowserViewControllerDelegate methods.
Step 7: Now in sendData method divide your image in data chunks and call sendData:toPeers:withMode :error method of MCSession object and pass data chunk in it to connected peer.
Step 9: Call sendData method from send button action method.
Step 8: Add appendFileData method to append all chunks and save file on receiver device and display alert message after image saved successfully in camera roll.
Step 9: Add MCSessionDelegate methods.

No comments:

Post a Comment