UIActivityViewController: LaunchServices: invalidationHandler called - uiactivityviewcontroller

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

Related

Must we have to download the remote file before using AirDrop?

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.

stuck with Social frameworks on ios device

I cannot get social frameworks to function correctly on my ios device, however it functions perfectly in the iOS simulator but not on my iPad, can anyone advise on where I may have gone wrong. Thanks in advance.
- (IBAction)sharefb:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:#"Share this app with your friends"];
[mySLComposerSheet addImage: [UIImage imageNamed:#"icon2.png"]];
[self presentViewController: mySLComposerSheet animated:
YES completion:nil];
}
[mySLComposerSheet setCompletionHandler:^
(SLComposeViewControllerResult result) {
NSString *output = [[NSString alloc] init];
switch (result) {
case SLComposeViewControllerResultCancelled:
output = #"Post Cancelled";
break;
case SLComposeViewControllerResultDone:
output = #"Posted successfully";
break;
default:
break;
}
}];
I just copy/pasted your code into a blank project and ran it on my iPad successfully, so I'm not exactly sure what the problem is but here's a couple of things you can try.
First, you use both of these lines in your code:
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
It is unnecessary, and unwise to call alloc/init on the composer right before composeViewControllerForServiceType which returns a SLComposeViewController object already. Omitting the first of those two lines could solve the problem.
Second, are you sure that "icon2.png" exists in the project? This shouldn't be causing the problem, but hey crazier things have happened.
Third, also unlikely but it is possible that you have some strange invisibles creating problems with the arguments of presentViewController due to your spacing and line break placement. Try rewriting the line to look like this:
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
Site note, your NSString *output is creating a memory leak, unless it is used for something else that you haven't included in your code. This is all going off of your original post which does not actually specify the problem. If you can be more specific, I can probably be more helpful.

Saving and Restoring Application State on iOS 6 without Storyboards

I have done test app following this tutorial
I try to do the same without using Storyboards and it isn't work. I have enabled state preservation and restoration in AppDelegate. I have assigned restorationIdentifier to all my controllers and their views. I think i have to implement some additional code in AppDelegate to restore rootviewcontroller, but i cannot find the right way to do this.
-(BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder
{
return YES;
}
-(BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder
{
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1 = [[[StateTestFirstViewController alloc] initWithNibName:#"StateTestFirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[StateTestSecondViewController alloc] initWithNibName:#"StateTestSecondViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.restorationIdentifier = #"TabBarController";
self.tabBarController.viewControllers = #[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Actually, your view controllers are restored between application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: so if you change your code to:
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *viewController1 = [[[StateTestFirstViewController alloc] initWithNibName:#"StateTestFirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[StateTestSecondViewController alloc] initWithNibName:#"StateTestSecondViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.restorationIdentifier = #"TabBarController";
self.tabBarController.viewControllers = #[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
return YES;
}
It worked for me. Also I recommend that you watch the WWDC 2012 Session 208 — Saving and Restoring Application State on iOS.
I had quite a few issues trying to implement this as well.
First of all, have you succeeded in making this work with storyboards?
Your code looks good and you shouldn't need anything else as there are only 2 requirements:
Set shouldRestoreApplicationState and shouldSaveApplicationState to YES in the AppDelegate
Set restoration ID's to All the UIViewControllers (UIViews don't need it)
I would suggest you pay attention to the way you "Kill" the App.
In the simulator :
Hit the simulator home button.
Stop the App with Xcode.
Play the App with Xcode.
Indeed, the system deletes your application state as soon as you kill the App from the multitask bar.
If you want it to work fine using the multitask bar, you have to set
"Application does not run in background" to YES in the Info.plist file.
Hope it helps ;)

Attach object using iOS6 UIActivityViewController

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.

Open Files from mail

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.

Resources