1

The user can share things through email from an UIActivityViewController. When the recipient receives the email, they have a link that they can click to take them to the app. However, currently the link takes them to the app store, which my app is not on yet. How can I change this so that they open the app on their device from the email? I am using the following code right now:

NSString *appName = [NSString stringWithString:[[[NSBundle mainBundle] infoDictionary]   objectForKey:@"CFBundleName"]];
NSURL *appStoreURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.com/app/%@",[appName stringByReplacingOccurrencesOfString:@" " withString:@""]]];

I changed my code to the following (Now I am showing all of the actions code, not just the ling):

NSString *shareCaption = captionText.text;
UIImage *shareImage = [UIImage imageWithData:_photo];
NSURL *appURL = [NSURL URLWithString:[NSString stringWithFormat:@"<BR><BR><BR><A HREF=\"http://myApp://\">Open App</A>"]];
NSArray *shareItems = @[shareCaption, shareImage, appURL];
UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil];
activity.excludedActivityTypes = @[];
[self presentViewController:activity animated:YES completion:nil];

However, when I changed the url to this the app crashes and I get the following message:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2]'

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
John55
  • 301
  • 2
  • 11
  • check this answer: http://stackoverflow.com/questions/419119/launch-an-app-from-within-another-iphone – William Hu Jan 31 '16 at 00:54
  • I looked at it, however in that answer, they are opening another application from their application. I need another application, mail app, to open my application. @WilliamHu – John55 Jan 31 '16 at 01:31
  • check this [link](http://stackoverflow.com/questions/11769874/open-iphone-app-from-an-email-link) – Bamsworld Jan 31 '16 at 01:45
  • @rmaddy I have looked at that question and the answers did not work. That is why I posted this so it may be a duplicate but those answers did not work. – John55 Jan 31 '16 at 03:24
  • Does your app register a custom URL scheme? Are you using a link with that custom URL scheme in your email message? You say the answer in the linked question doesn't work. But it does. If it isn't working for you then you need to post a question explaining exactly what you are doing with regard to the custom URL scheme, what you have setup, and what happens when the user taps on the custom URL scheme link. – rmaddy Jan 31 '16 at 03:28
  • So I tested their answer and my app crashed when the share button is pressed so I can not test the URL scheme link. @rmaddy However, when I do not use the link that their correct answer gave, it runs fine – John55 Jan 31 '16 at 03:34
  • Do you really think the string `


    Open App` is a value `NSURL`?
    – rmaddy Jan 31 '16 at 03:46
  • I am adding what the duplicate question said to add @rmaddy – John55 Jan 31 '16 at 03:47
  • That's part of the email body. It's not a URL you pass to an activity controller. – rmaddy Jan 31 '16 at 03:48
  • Okay. I was unaware of that. Typically links are supposed to be URL's so what should I change to from NSURL? @rmaddy – John55 Jan 31 '16 at 03:51

0 Answers0