-4

I am having an app in which I want to open native application without opening UI Activityviewcontroller.

On click of a button, I want to open the native app.

I have set the URL of an app on click of a button, but still it is showing an activityviewcontroller.

How to avoid UIActivityViewController?

Thanks in advance.

Edited

I am sharing an image on instagram on click of a button.

Here is my code.

NSURL *instagramURL = [NSURL URLWithString:@"instagram://"];

                if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
                {

                    CGRect rect = CGRectMake(0 ,0 , 0, 0);
                    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
                    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

                    UIGraphicsEndImageContext();
                    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                    NSString* documentsDirectory = [paths objectAtIndex:0];

                    imagename=[NSString stringWithFormat:@"FameFace.ig"];
                    NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imagename];
                    ////NSLog(@"%@",fullPathToFile);

                    igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", fullPathToFile]];

                    self.dic.UTI = @"com.instagram.photo";
                    self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
                    self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
     self.dic.annotation = [NSDictionary dictionaryWithObject:@"Image" forKey:@"InstagramCaption"];
   [self.dic presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];

enter image description here

As shown in the screenshot it opens up in UIActivityView.

Is it possible that if I click on a button it instantly navigates me to the native app without showing that ActivityViewController?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Manthan
  • 3,856
  • 1
  • 27
  • 58

1 Answers1

4

You can open an app using [[UIApplication sharedApplication] openURL:appURL]

It would look something like this in your case:

NSURL *instagramURL = [NSURL URLWithString:@"instagram://"];

if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
    NSURL * openInstagramURL = nil;
    //TODO: construct your proper instagram URL here. 
    [[UIApplication sharedApplication] openURL:openInstagramURL];
}

The key thing is that you have to properly construct your URL such that the receiving application, in this case Instagram would perform the correct action.

Engin Kurutepe
  • 6,719
  • 3
  • 34
  • 64
  • NSURL * openInstagramURL = nil; [[UIApplication sharedApplication] openURL:openInstagramURL]; I added this two lines but it still showing me tha ActivityView. – Manthan Jun 06 '13 at 13:16
  • 1
    first of all you have to construct the proper URL for instagram, nil is obviously not going to work. And second you have to delete your code with `UIDocumentInteractionController` – Engin Kurutepe Jun 06 '13 at 13:27