Take pictures on other iOS devices using bluetooth

2019-03-06 03:21发布

问题:

I'd appreciate if someone with iOS bluetooth experience could show me how to take pictures on other iOS devices using bluetooth classes. This app lets users login/register and afterwards take and upload pics. http://www.raywenderlich.com/13511/how-to-create-an-app-like-instagram-with-a-web-service-backend-part-12 My goal is to, on tap of a user photo in the apps uiscrollview (which displays all uploaded photos), activate the snapStillImage method of AVFoundation below.

//this code takes a picture
- (void)snapStillImage //this takes a picture via [self snapStillImage] in viewDidLoad
{
dispatch_async([self sessionQueue], ^{
    // Update the orientation on the still image output video connection before capturing.
    [[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]];
    // Flash set to Auto for Still Capture
    [ViewController5 setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]];
    // Capture a still image.
    [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
        if (imageDataSampleBuffer)
        {
            NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];

            photo.image = [[UIImage alloc] initWithData:imageData];
            [[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[photo.image CGImage] orientation:(ALAssetOrientation)[photo.image imageOrientation] completionBlock:nil];
            [self uploadPhoto];
}
    }];
});
}

Id imagine every user would need to become a central/peripheral at login? I have 0 experience with setting up BLE on iOS let alone equipped with server functions. Any ideas or tips would be awesome.

回答1:

You should have a look at the iOS7+ MultipeerConnectivity Framework, which allows nearby devices to communicate amongst themselves. This is easy to send message from one device to (an)other device(s) through this framework, wrapped into a NSData variable.

This framework is really easy to set up, but do not hesitate to have a look at GitHub search results.