I am sending the remote file (for example: image file, pdf file ... ) to Airdrop.
I have only the direct link of this file : http://example.com/xxx/png.
Currently, I am doing something like below code
NSString *filePath = self downloadFileFromServerWithURL
NSURL *urlFilePath = [NSURL fileURLWithPath:filePath];
NSArray *Items = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:indexPath.row],
urlFilePath,nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:Items applicationActivities:[NSArray arrayWithObjects:xxx, yyy,nil];
[self presentViewController:activityViewController animated:YES completion:nil];
So, my question is, how can I share the remote file with Airdrop without downloading it before?
I show a lot of iOS softwares can do that, like DropBox
Thank you
you should look into using a subclass of UIActivityItemProvider which will let you asynchronously get/generate the actual item to be shared. The AirDrop sample code has an example of this.
Related
i am using UIActivityViewController in ios8
and using ARSafariActivity.h
NSURL *newsURL = [NSURL URLWithString:string];
NSString *newsTitle = #"..."
ARSafariActivity *safariActivity = [[ARSafariActivity alloc] init];
UIActivityViewController *avc = [[UIActivityViewController alloc]
initWithActivityItems:#[newsTitle, newsURL]
applicationActivities:#[safariActivity]];
[avc setRestorationIdentifier:#"Activity"];
[self.navigationController presentViewController:avc animated:YES completion:nil];
Everything is working properly, but when i test app in my iPhone the console show this:
LaunchServices: invalidationHandler called
How i can fix that?
Seem to be discussed/answered in several threads, e.g. here: This is a bug on Apple's side
In short - it's debug message from iOS and you should not care about it
Here i have demo code for saving NSMutableString in to File (FileName.dat)
NSError* error = nil;
NSMutableString* dat = [[NSMutableString alloc] initWithCapacity:1];
BOOL result = [dat writeToFile:#"FileName.dat" atomically:YES encoding:NSUTF8StringEncoding error:&error];
but i have two different output while rung it in iOS7 and iOS8beta5
Output XCode5+iOS7
Output XCode5+iOS8
While running it in iOS7 it shows that there in an error in parsing file path,
but in iOS8beta5 it crash by saying that [NSFileManager fileSystemRepresentationWithPath:] have nil or empty path.
Question :
In both SDK iOS8 and iOS7 it take NSError as argument to return error, so i believe that it should return error instead of crashing application
Is apple mansion any changes regarding it, If yes then please give me reference link for the same.
The path you pass to [NSData writeToFile:atomically:] is not complete and should be a full path.
That is normally done by getting the path to the Documents folder and appending that filename.
The problem is your filename, #"FileName.dat", there is no path to the directory to save to. NSFileManager does not do this itself, you'll want to save to the Documents folder normally. Here is the code I usually use:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:myFileName];
So I am trying to get my app to stream a video located on Amazon S3. So far, I can do that with the MediaPlayer Tutorial from Apple no problem: https://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html
However, I am using RestKit in my app and therefore AFNetworking as well. I see that AFNetworking is using caching, so I was wondering if it was possible to do the same with videos? I don't know how to stream a video using AFNetworking. So that would be a good start. I can download a movie using AFNetworking... but can I stream with it or I should just use the streaming system given by #import
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"https://s3.amazonaws.com/leclerc/videos/sop/IMG_0141.MOV"]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:#"IMG_0141.MOV"];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(#"Successfully downloaded file to %#", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"Error: %#", error);
}];
[operation start];
For example, if I watch a music clip on Vevo and then rewatch 5 minutes later, do I have to redownload it on my iPad?! This is all new to me, so sorry for my ignorance!
I'm migrating to use the UIActivityViewController for sharing in iOS6, but I can't figure out how to create email attachment objects to be included when sharing by email.
The corresponding code in iOS5 is:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[picker addAttachmentData:data mimeType:#"application/XXX" fileName:fileName];
You have very limited control over UIActivityViewController, but if you're attaching well-know mime types, I found you can get it to work correctly by providing the associated file extension in a file URL. For example, if your attachment is a vCard, use the ".vcf" extension in the file URL:
NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
// The file extension is important so that some mime magic happens!
NSString *filePath = [docsPath stringByAppendingPathComponent:#"vcard.vcf"];
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
[data writeToURL:fileUrl atomically:YES]; // save the file
// Now pass the file URL in the activity items array
UIActivityViewController *avc = [[UIActivityViewController alloc] initWithActivityItems:
#[#"Here's an attached vCard", fileUrl] applicationActivities:nil];
[vc presentModalViewController:avc animated:YES];
For anyone wondering why their files aren't being shared using UIActivityViewController to apps like DropBox and other generic file handling applications, what you really want is a UIDocumentInteractionController.
Use it something like this:
class ViewController {
var openInController:UIDocumentInteractionController!
init() {
openInController = UIDocumentInteractionController(URL: docURL)
}
func shareDoc {
openInController.presentOptionsMenuFromRect(CGRectZero, inView: self.view, animated: true)
}
}
From what I can tell you can't do this with the UIActivityViewController -- I can't even manage to make it present HTML content for the message body -- so you may be better off using SLComposeViewController.
I'm struggling with file handling on iOS.
I could already assign my file type to iOS and I can launch my app from mail with a special file.
My app is launching and I'm firing this method:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
if([url isFileURL])
{
NSString *fileConts = [[NSString alloc] initWithContentsOfFile:[NSString stringWithFormat:#"%#", url] encoding:NSUTF8StringEncoding error:nil];
[self.viewController openFile:fileConts];
fileConts = nil;
}
return YES;
}
The openFile:(NSString) method is declared in the viewController and sets the value of a textView (for now). This method works fine. I tested it via [self.viewController openFile:#"test"];.
But when my application launches with file attached, the textView keeps empty.
It seems that it doesn't adopt the string value or that it can't read the string value.
handleOpenURL will be called only if application already running (in the background).
To make sure you correctly dispatch incoming files, you also need to check it on the app launch:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *url = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
// Process url here
}
It's good idea to have 1 URL dispatcher called both from handleOpenURL and didFinishLaunchingWithOptions.
I could solve my problem.
My mistake was to initWithContentsOfFile:(NSString *)
I updated my code with
NSString *fileConts = [[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
Now I'm happy!
Thanks for help.