I use i-tunes in-app links like:
NSString *app_link = #"samuraivszombiesdefense";
NSString *link = [#"itms-apps://itunes.com/apps/"stringByAppendingString:app_name];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:link]];
Do somebody happen to know: what is this 'app name' - name of application record (except forbidden symbols) created in itunes (what you can see on iTunesConnect->'Manage Your Apps' screen) or 'App Name' field from 'Metadata and uploads' when editing version details in iTunesConnect?
I mean if app's metadata has many languages, 'App Name' for every language is different. Will link like 'itms-apps://itunes.com/apps/appname' work if appname will be english app name?
Ok, here's my solution.
I decided to use URLs like:
http://itunes.apple.com/app/idXXXXXXXXX?mt=8, where XXXXXXXXX - my app's id.
There is no country prefix, so I suppose it will work global, not only in USA or Germany.
Or not?
This kind of links can cause multiple redirects. So to avoid them I've used such code (based on code from Apple docs and works pretty well):
#interface iTunesOpener ()
{
NSURL *iTunesURL;
}
- (void)openAppLinkFromAppId:(NSString *) appid;
- (void)openReferralURL:(NSURL *)referralURL;
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response;
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
#end
#implementation iTunesOpener
- (void)openAppLinkFromAppId:(NSString *) appid
{
NSString *iTunesLink = [NSString stringWithFormat:#"http://itunes.apple.com/app/id%#?mt=8", appid];
NSURL* url = [NSURL URLWithString:iTunesLink];
[self openReferralURL: url];
}
// Process a LinkShare/TradeDoubler/DGM URL to something iPhone can handle
- (void)openReferralURL:(NSURL *)referralURL
{
NSURLConnection *con = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:referralURL] delegate:self startImmediately:YES];
[con release];
}
// Save the most recent URL in case multiple redirects occur
// "iTunesURL" is an NSURL property in your class declaration
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response
{
iTunesURL = [response URL];
if( [iTunesURL.host hasSuffix:#"itunes.apple.com"])
{
[connection cancel];
[self connectionDidFinishLoading:connection];
return nil;
}
else
{
return request;
}
}
// No more redirects; use the last URL saved
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[[UIApplication sharedApplication] openURL:iTunesURL];
}
#end
Edit: App's link will not work if you just use the same link for all countries. Because the link in different country is different. For example Facebook's link in China has a '/cn' between '/com' and '/app'. See the picture:
To be extreamly concise:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms://itunes.com/apps/appname"]];
If you want to send to all the apps for a developer, use
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms://itunes.com/apps/developername"]];
If you want to open a specific app with your company name included in the URL:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms://itunes.com/apps/developername/appname"]];
And you can refer to this question for more:How to link to apps on the app store
The best solution we've found is to avoid trying to predict the URL, and create a custom URL redirect like http://mycompany.com/redirects/my-app-itunes which you can update to redirect to the correct URL once you know it.
The exact string you must use is difficult to get right, especially when you have special characters, spaces etc. The rules might even change, or Apple could decide to change something. It's best to keep the URL under your control.
If you really want to go this route, see this documentation from Apple. It details exactly what you need to do to transform the app name into a short friendly iTunes URL:
Remove all whitespace
Convert all characters to lower-case
Remove all copyright (©), trademark (™) and registered mark (®) symbols
Replace ampersands ("&") with "and"
Remove most punctuation (See Listing 2 for the set)
Replace accented and other "decorated" characters (ü, å, etc.) with their elemental character (u, a, etc.)
Leave all other characters as-is.
The application name should be the name as it appears in iTunes Connect's application list (non-localized). The best thing is to test this however.
Finally, from Apple:
These itunes.com URLs are provided as a convenience and are not
guaranteed to link to a particular application or company. Be sure to
test your URLs before using them in any marketing or other public
materials. If there are naming conflicts, continue using the standard
itunes.apple.com URLs, which contain a unique numerical identifier
within the URL.
Related
I am working on custom URL scheme basically i am new with us functionality.
What i done before?
I implemented this successfully,i create simple url "myApp" now when i hit this url on safari like (myApp://) its launch my application.
My code
i used:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
What i want?
Basically i want to implement two things that is:
when an user hit a link on safari if an application is installed on device,through that link application should launch.That point i already done successfully.
The second point which i can't done yet,after trying a lot but i couldn't found any solution yet,that is:
If an application is not installed on device that link should redirect to app store where user can installed application.
If it is possible,then please tell me how to do that,please refer me any link,example or your answer also help me.Thanks in advance
What you are describing is called Deep Linking. It's a very common app feature to implement — most apps have it — and conceptually, it seems like an easy thing to build. However, it's complicated to get right, and there are a lot of edge cases.
You basically need to accomplish two things:
If the app is installed: open the app and route users to the correct content inside it.
If the app is NOT installed: forward users to the App Store so they can download it. Ideally, also route users to the correct content inside the app after downloading (this is known as 'deferred deep linking').
While not required, you'll also probably want to track all of this activity so you can see what is working.
If the app is installed
Your existing custom URI scheme fits into this category. However, Apple has decided that custom URI schemes are not a good technology, and deprecated them with iOS 9 in favor of Universal Links.
Apple is right about this. Custom URI schemes have a number of problems, but these are the biggest:
There is no fallback if the app isn't installed. In fact, you get an error.
They often aren't recognized as links the user can click.
To work around these, it used to be possible to use a regular http:// link, and then insert a redirect on the destination page to forward the user to your custom URI scheme, thereby opening the app. If that redirect failed, you could then redirect users to the App Store instead, seamlessly. This is the part Apple broke in iOS 9 to drive adoption of Universal Links.
Universal Links are a better user experience, because they are http:// links by default and avoid nasty errors. However, they are hard to set up and still don't work everywhere.
To ensure your users end up inside the app when they have it installed, you need to support both Universal Links and a custom URI scheme, and even then there are a lot of edge cases like Facebook and Twitter which require special handling.
If the app is NOT installed
In this case, the user will end up on your http:// fallback URL. At this point, you have two options:
Immediately forward the user directly to the App Store.
Send the user to your mobile website (and then use something like a smart banner to give them the option of going to the App Store).
Most large brands prefer the second option. Smaller apps often go with the first approach, especially if they don't have a website.
To forward the user to the App Store, you can use a Javascript redirect like this:
<script type="text/javascript">
window.onload = function() {
window.location = "https://itunes.apple.com/app/id1121012049";
};
</script>
Until recently, it was possible to use a HTTP redirect for better speed, but Apple changed some behavior in Safari with iOS 10.3, so this no longer works as well.
Deferred deep linking
Unfortunately there's no native way to accomplish this last piece on either iOS or Android. To make this work, you need a remote server to close the loop. You can build this yourself, but you really shouldn't for a lot of reasons, not the least of which being you have more important things to do.
Bottom line
Deep linking is very complicated. Most apps today don't attempt to set it up by building an in-house system. Free hosted deep link services like Branch.io (full disclosure: they're so awesome I work with them) and Firebase Dynamic Links can handle all of this for you, and ensure you are always up to date with the latest standards and edge cases.
See here for a video overview I made of everything you need to know about this.
In AppDelegate.m call this:
-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options;{
NSLog(#"url recieved: %#", url);
NSLog(#"query string: %#", [url query]);
NSLog(#"host: %#", [url host]);
NSLog(#"url path: %#", [url path]);
NSDictionary *dict = [self parseQueryString:[url query]];
NSLog(#"query dict: %#", dict);
if ([[url host] isEqualToString:#"login"]) {
[self setupHomeScreen:NO type:#"" entityId:#""];
[self _endSession];
return YES;
} else if ([[url host] isEqualToString:#"smartoffice"]) {
NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
NSRange needle = [url.absoluteString rangeOfString:#"?" options:NSCaseInsensitiveSearch];
NSString *data = nil;
if(needle.location != NSNotFound) {
NSUInteger start = needle.location + 1;
NSUInteger end = [url.absoluteString length] - start;
data = [url.absoluteString substringWithRange:NSMakeRange(start, end)];
}
for (NSString *param in [data componentsSeparatedByString:#"&"]) {
NSArray *keyvalue = [param componentsSeparatedByString:#"="];
if([keyvalue count] == 2){
[result setObject:[keyvalue objectAtIndex:1] forKey:[keyvalue objectAtIndex:0]];
}
}
NSString *entityID = ([result objectForKey:#"secondparameter"]);
NSString *type = [result objectForKey:#"parameter"];
[self setupHomeScreen:YES type:type entityId:entityID];
//[self setupHomeScreen:YES type:#"TASK" entityId:#"160315"];
return result;
} else {
NSLog(#"myApp is not installed");
[self setupHomeScreen:NO type:#"0" entityId:#"0"];
}
return NO;
}
Open Xcode, got to Project Settings -> Info, and add inside ‘The URL Types” section a new URL scheme.
That is the scheme ://resource. So we go ahead and type com.myApp://
Fo me its backofficeapp://
Now use this link on Safari
backofficeapp://smartoffice/1?parameter=TASK&secondparameter=157536
Where
parameter = “TASK”
secondparameter = “taskID” // #iOS Mobile 2020 = 157536
This parameter is for landing on a specific screen.
Remember this URL won’t work if the app is not installed.
i'm trying to open an app in appstore from an UIAlertView When the otherButtonTitle. The problem is nothing is happening.
I've checked when the otherButton is pressed if this method is called and it is. The problem lies in the openURL i guess. the appId contain an name of an app without any whiteSpace like "youtube". How come the link is not opening? i've tried looking in other threads and this is the code that should open an app in appstore
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex: (NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
NSString *appId = [[otherArray objectAtIndex:currentRow] objectForKey:#"link"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: #"itms-apps://itunes.apple.com/app/%#?mt=8", appId]]];
}
}
You need to break it down into smaller steps and debug the steps.
First, is the didDismiss method being called.
Next, is the code inside the if statement being executed.
The easiest way to figure this out is to set a breakpoint on the code that assigns appID and then make sure your code breaks there.
After that line executes, make sure appId contains the string you expect it to.
Net, you should rewrite the last line into steps that first create the URL, THEN call openURL. Step through the code that creates the URL to make sure it is being created correctly.
You might want to copy the URL string and paste it into a browser to see if it works from there.
i am trying to provide the rate this app functionality into my application hence i added the below code
- (void)gotoReviews
//------------------
{
NSString *str = #"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa";
str = [NSString stringWithFormat:#"%#/wa/viewContentsUserReviews?", str];
str = [NSString stringWithFormat:#"%#type=Purple+Software&id=", str];
str = [NSString stringWithFormat:#"%#APPid", str];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
str = [NSString stringWithFormat:#"%#APPid", str]; here i have to mention my app id.i see the appid into the provisioning portal as following 546F5QMTE4.com.XXXX.XXXX into the APp id section.
Is that the "546F5QMTE4" string need to placed? am i right is that correct id?
please let me know
You can do this in many ways:
Direct approach:
#define APP_ID XXXXX //id from iTunesConnect
NSString *reviewURL = [NSString stringWithFormat:#"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d",APP_ID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:reviewURL]];
Try with Appirator in app delegate:
[Appirater setAppId:#"552035781"];
[Appirater setDaysUntilPrompt:1];
[Appirater setUsesUntilPrompt:10];
[Appirater setSignificantEventsUntilPrompt:-1];
[Appirater setTimeBeforeReminding:2];
[Appirater setDebug:YES];
You can get source: Here.
Add Appirater.h and Appirater.m to your project.
For more information about integration: Here
:)
No, it is not that number. You have to go to the iTunesConnect -> Manage Your Apps, choose your app, then look under "App Information" for Apple ID (digits only).
Of course be sure that you have actually a record for your app. If not, just make it (Add New App button).
iRate is best https://github.com/nicklockwood/iRate
The one that I use and works wonders on iOS 5+ (also available for Mac OS X, but this answer is focused on the iOS portion) and up on all devices (iPad, iPhone, iPod Touch) is iRate.
It uses a uialertview and storekit to ask the user for a rating (or to remind them later). Everything is customizable, from the name of the Cancel Button Title to the Interval at which it reminds the user.
By default, iRate automatically opens when certain requirements are met (ex. app launched X number of times, user passed X number of levels), but you can also use a variety of methods and your own logic (with the help of iRate methods) to manually display an iRate popup.
Setup
To install,
just drag the header (.H) file the implementation (.M) file, and the iRate Bundle (for localization) into your project.
Import the header in your AppDelegate: #import "iRate.h"
Add the StoreKit Framework to your project - More on StoreKit from Apple Documentation
Add the following method to your app delegate: + (void)initialize
The properties can be set in the initialize method, however none of them are required (iRate can automatically find all of this information).
No, it isn't. It's rather a numeric ID with a few digits, something like this:
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=389801252&pageNumber=0&sortOrdering=1&type=Purple+Software
This will only be live when your application has been approved by Apple and it's already on the AppStore (in case of an intentionally delayed launch).
Furthermore, the way you're composing that poor URL string is simply horrible. Don't abuse format strings! You have a constant string here, so you don't even need any call to + [NSString stringWithFormat:]. Even if you wanted to alter the app ID, you could do that using one single formatting statement:
NSString *str = [NSString stringWithFormat:#"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=%#&pageNumber=0&sortOrdering=1&type=Purple+Software", appID];
I'm trying to implement a job search App. The results are shown to the user in a UITableView.
When a user clicks on a cell, it should open the original Job announcement.
To do this, i implemented the following method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *url = [[NSString alloc]init];
url=[[[xmlParser jobs] objectAtIndex:indexPath.row] urlAddress]; //UrlAddress is an instance variable of type NSString
NSURL *urlJobDetail = [NSURL URLWithString:(url)];
[[UIApplication sharedApplication] openURL: urlJobDetail];
}
The interesting part is: if i type an NSString like #"http://www.google.com" or any other link, it works. But when i try to open a "the urlJobDetail", it just doesn't work... Nothing happens at all...
And i searched it in stackoverflow.com and found this:
url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Than the url works but this method changes the original url address and adds lots of % signs like:
"http://www.google.com%20 %20 %20"
So i get an page not found error.
I don't understand why this function doesn't accept a regular NSString variable as?
I checked it with NSLog and the url seems to be perfectly in order.
Any help would be much, very much appreciated !
Thanks in advance
Because it's URL specification related restrictions
Spaces and control characters in URLs must be escaped for transmission in HTTP, as must other disallowed characters... It is necessary to encode any characters disallowed in a URL, including spaces and other binary data not in the allowed character set, using the standard convention of the "%" character followed by two hexadecimal digits.
Apple has explained in "Launching the App Store from an iPhone application" how one can make an affiliate link to the app store and handle the redirect in background so it doesn't annoy the user. But it would be even better not to have the redirect at all. I seem to remember seeing a way to do that, but now I can't find it anywhere.
Is it possible to make an affiliate link from an iOS app to the app store without any redirect at all?
EDIT: To clarify, I am talking about a Linkshare affiliate link.
EDIT 2: I'm getting closer. I have this link, which I grabbed straight off of linkshare's "text links" page. When using k1th's trick below, works without any redirects on the iPad, but still has one redirect on an iPod touch [and presumably iPhone]. I speculate that the redirect may be to switch from top iPad apps to top iPhone apps, but I don't know that for sure.
http://click.linksynergy.com/fs-bin/click?id=sf2bW7QX/qU&offerid=146261.10005745&type=3&subid=0
Yes, you may have slashes in the params (that's because it's a slash after the question mark starting the parameter part of the URL.
Regarding skipping Mobile Safari to process the affiliate links:
You can either set up a hidden UIWebView to handle the redirect or do all that in the URL loading system yourself.
This is with a hidden WebView:
NSURLRequest *r = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://click.linksynergy.com/fs-bin/click?id=sf2bW7QX/qU&offerid=146261.431296703&type=2&subid=0"]];
testWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
testWebView.hidden = YES;
testWebView.delegate = self;
[testWebView loadRequest:r];
the delegate:
#pragma mark - UIWebViewDelegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.scheme isEqualToString:#"itms"] &&
[[UIApplication sharedApplication] canOpenURL:request.URL]) {
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
}
return YES; // go on redirecting
}
testWebView needs to be an instance var and the view controller itself needs to be a <UIWebViewDelegate>. You also need to set the webview delegate to nil somewhere (e.g. in -dealloc)
I take it the reason you don't want redirects is to
avoid the Safari browser from popping up
avoid redirection within the App Store app itself
I would prefer k1th's solution, but failing that (I suppose it could fail #2 above), I assume the problem is that the first itms link is not the "final" one. One solution would be to simply hard-code the URL (or provide it by some other means):
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL myAppUrl = ....
if ([request.URL.scheme isEqualToString:#"itms"] &&
[[UIApplication sharedApplication] canOpenURL:myAppURL]) {
[[UIApplication sharedApplication] openURL:myAppURL];
return NO;
}
return YES; // go on redirecting
}
A cleaner solution would be to read the app ID off the itms link in the request.URL and format a new URL using the pattern that will take you directly to your app.
There is a much cleaner solution directly from Apple here: https://developer.apple.com/library/ios/#qa/qa1629/_index.html
And for brevity, here is the code from that page:
// Process a LinkShare/TradeDoubler/DGM URL to something iPhone can handle
- (void)openReferralURL:(NSURL *)referralURL {
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:referralURL] delegate:self startImmediately:YES];
[conn release];
}
// Save the most recent URL in case multiple redirects occur
// "iTunesURL" is an NSURL property in your class declaration
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response {
self.iTunesURL = [response URL];
return request;
}
// No more redirects; use the last URL saved
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[[UIApplication sharedApplication] openURL:self.iTunesURL];
}
I found this document and I think it's giving me the answer. I always have a hard time deciphering these things, but I think it says that what I do is start with a basic link:
http://itunes.apple.com
then append a partnerId of 30, plus my linkshare affiliate token, which I think is
sf2bW7QX/qU
to end up with the following:
http://itunes.apple.com?partnerId=30&id=sf2bW7QX/qU
I got what I think is my id by following the instructions in the Apple doc, which basically say to grab the id parameter from a random linkshare link. The link I used for the purpose was this:
<IMG border=0 src="http://a464.phobos.apple.com/us/r30/Music/b9/7f/91/mzi.kbjyfypr.170x170-75.jpg" ><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=sf2bW7QX/qU&bids=146261.431296703&type=2&subid=0" >
I'm still quite unsure about the whole thing. Can my linkshare affiliate token really have a slash in it?
This answers your question:
http://www.apple.com/itunes/affiliates/resources/documentation/linking-to-the-itunes-music-store.html#apps
BTW, I find this whole affiliate program too complicated. I looked into it and I don't think it's worth the 5% commission.