A
A
Alexander Tikhonov2015-02-19 21:53:50
Objective-C
Alexander Tikhonov, 2015-02-19 21:53:50

How to transfer data between ios applications?

There is a task to transfer data from one application to another. I looked in the direction of extensions, and specifically the Document Provider, but did not fully understand how to use it and whether it suits my needs.
The task is complicated by the fact that I do not have a Developer Program and therefore there are no options for working through iCloud.
Any ideas how to deal with this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2015-02-20
@alexyat

Everything is quite simple, the application that sends the data must create a
UIDocumentInteractionController;

UIDocumentInteractionController *_controller;

if(!_controller)
            _controller = [[UIDocumentInteractionController alloc]init];
        _controller.delegate = self;
        NSURL *documentURL = @"тут должен быть урл в файловой системе, в который записаны данные которые нужно передать";
        _controller.URL = documentURL;
        if(![_controller presentOpenInMenuFromRect:cell.frame inView:self animated:YES])
        {
            NSLog(@"can't open in another app");
        }
        else
            NSLog(@"Open in another app");

// ну и делигат методы

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
    
    return  self;// это вьюв контроллер в котором будет всплывающее меню с выбором аппа который будет открывать.
}

- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application {
    
    NSLog(@"Starting to send this puppy to %@", application);
}

- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application {
    
    NSLog(@"We're done sending the document.");
}

in the receiving app, you need to add Exported Type UTIs to Info.plist, and add launchOptions processing when starting the app
something like this
NSURL *url = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
NSData* data = [NSData dataWithContentsOfURL:url];

and do whatever you want with this NSData, convert it to what you need.
more details on how to add the ability to open files to your app is written here . The main thing is that the file that you created in the first app should have the same extension that you register in the second.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question