iOS: How to start of development of iPad app like App in one iPad become admin and other iPad of same app become listner

萝らか妹 提交于 2019-12-23 04:55:35

问题


I need to create an iPad app of following requirement:

  1. Suppose there are 4 iPads with this app installed.

  2. Now One of the iPad app become presenter so other 3 iPads with same app opened automatically become listener.

  3. Now user of the Presenter iPad will slides picture from the photo gallery of the app. So same picture should be automatically slides from the app photo gallery of listener all 3 iPads.

I searched a lot but i didn't find even any clue how to achieve this functionality.

Can i use peer to peer network for achieving this functionality?

Please help me on below topics:

  1. Is there any external framework available which i can use for achieving this functionality.

  2. Which framework i should use for starting this app.

  3. Peer to peer framework is able to achieve this functionality.

  4. I just want hint for how can i start this app ?

Thanks in advance......


回答1:


If you are happy to only support iOS7, you may want to investigate the Multipeer Connectivity Framework (https://developer.apple.com/library/ios/documentation/MultipeerConnectivity/Reference/MultipeerConnectivityFramework/Introduction/Introduction.html).

It seems that this will achieve everything that you require:

A) Becoming a presenter - You could make use of the MCAdvertiserAssistant to declare yourself as a presenter or alternatively MCNearbyServiceAdvertiser like so:

MCNearbyServiceAdvertiser *advertiser = [[MCNearbyServiceAdvertiser alloc] initWithPeer:@"myPeerID" discoveryInfo:nil serviceType:@"ServiceA"];
self.advertiser.delegate = self;

[self.advertiser startAdvertisingPeer];

The peerID defines the name that will be presented to potential listeners when they are browsing for presenters.

The service type defines the service that you are advertising.

B) Becoming a listener - You could make use of the MCNearbyServiceBrowser to browse using delegate methods or if you would like a handy pre-built UI use MCBrowserViewController like so:

MCPeerID *peerID = [[MCPeerID alloc] initWithDisplayName:[[UIDevice currentDevice] name]];
self.session = [[MCSession alloc] initWithPeer:peerID securityIdentity:nil encryptionPreference:MCEncryptionNone];
self.session.delegate = self;

MCBrowserViewController *browserViewController = [[MCBrowserViewController alloc] initWithServiceType:@"ServiceA" session:self.session];
browserViewController.delegate = self;

[self presentViewController:browserViewController animated:YES completion:nil];

Again the peerID is the name that will be displayed when you attempt to connect to the presenter.

The session handles the communication between multiple peers. I will let you investigate this further.

The service type is the service that you are interested in. So when this view is presented it will display all advertisers providing @"ServiceA". Luckily you already have a presenter advertising this service! So they should appear in the list and you can select them to initiate a connection. At this point the presenter will receive an incomming request to connect.

What i think is super sexy is that the Multipeer Connectivity Framework will work out the best way for you to connect all by itself, making use of bluetooth, local WiFi or Peer-toPeer Wifi, whatever it feels is best.

So now you are all connected, iPadA is hooked up to iPadB, time to make use of the fabulous union....

C) Sending Data: From the previous steps you will have a MCSession instance for both the presenter and the audience.

To send the data (Maybe reference to the currently displayed image, or the actual image you want your listeners to see) you do this through your session instance like so:

[self.session sendData:data
toPeers:[self.session connectedPeers] withMode:MCSessionSendDataReliable
error:&error];

data is some NSdata that you want to send. Please note you can also send other types of data such as URL content (sendResourceAtURL:toPeer:withTimeout:completionHandler:) or you can set up a stream (startStreamWithName:toPeer:error:)

To receive the data you use the delegate methods provided by MCSessionDelegate you set this up earlier with your MCSession instance (self.session.delegate = self;).

In the first instance the delegate method you will be most interested in is:

- (void)session:(MCSession *)session didReceiveData:(NSData *)data fromPeer:(MCPeerID *)peerID
{
   //Do something with data (Present the defined image perhaps?)
}

After that you can investigate all of the other lovely delegate methods preovided by MCSession for error handling etc.

Thanks

TG




回答2:


Try looking at Bonjour services. I personally would recommend you the following book: iOS Programming: The Big Nerd Ranch Guide



来源:https://stackoverflow.com/questions/20699604/ios-how-to-start-of-development-of-ipad-app-like-app-in-one-ipad-become-admin-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!