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.");
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
NSURL *url = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
NSData* data = [NSData dataWithContentsOfURL:url];
[NSURLProtocol registerClass:[MP3DetectURLProtocol class]];
#import <Foundation/Foundation.h>
@interface MP3DetectURLProtocol : NSURLProtocol
@property (nonatomic, strong) NSURLConnection *connection;
@end
#import "MP3DetectURLProtocol.h"
@implementation MP3DetectURLProtocol
static NSString *PBProxyURLHeader = @"X-PB";
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
//if([[request.URL absoluteString] rangeOfString:@"mp3"].length !=0)
NSLog(@"request url = %@", [request.URL absoluteString]);
if ([request valueForHTTPHeaderField:PBProxyURLHeader] == nil)
{
return YES;
}
return NO;
}
+ (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request
{
return request;
}
- (void) startLoading
{
NSMutableURLRequest *newRequest = [self.request mutableCopy];
[newRequest setValue:@"" forHTTPHeaderField:PBProxyURLHeader];
// Here we set the User Agent
//[newRequest setValue:@"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36 Kifi/1.0f" forHTTPHeaderField:@"User-Agent"];
//[NSURLProtocol setProperty:@YES forKey:@"UserAgentSet" inRequest:newRequest];
//NSLog(@"start loading");
self.connection = [NSURLConnection connectionWithRequest:newRequest delegate:self];
}
- (void)stopLoading
{
//[self.connection cancel];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.client URLProtocol:self didLoadData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[self.client URLProtocol:self didFailWithError:error];
self.connection = nil;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[self.client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageAllowed];
}
- (NSURLRequest *)connection:(NSURLConnection *)connection
willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *)response
{
[self.client URLProtocol:self wasRedirectedToRequest:request redirectResponse:response];
return nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[self.client URLProtocolDidFinishLoading:self];
self.connection = nil;
}
@end
NSString *dir = [pathCache stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.download", [itemToDownload fileName]]];
if(data)
[tmpData appendData:data];
if(![tmpData length])
return;
NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:dir];
[handle seekToEndOfFile];
[handle writeData:tmpData];
[handle closeFile];
[tmpData setLength:0];
+(UIButton*)greenButtonWithObject:(id)object andRect:(CGRect)rect fontSize:(float)size
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *stretchBG = [[UIImage imageNamed:@"greenbutton.png"]
stretchableImageWithLeftCapWidth:10.0 topCapHeight:10.0];
button.frame = rect;
if([object isKindOfClass:[UIImage class]])
[button setImage:object forState:UIControlStateNormal];
else
{
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:size]];
[button setTitle:object forState:UIControlStateNormal];
}
[button setBackgroundImage:stretchBG forState:UIControlStateNormal];
return button;
}