Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-05-2009, 11:52 AM   #1 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 624
DenVog is on a distinguished road
Question Using LinkShare to Launch App Store

Can anyone offer insight on how to process a LinkShare URL so that it opens App Store on the iPhone without multiple redirects?

I originally had a button opening URLs stored as a string called "buyUrlString" in a dictionary file, and it worked fine.
Code:
- (IBAction) buyButton:(id)sender {
        NSURL *buyUrl = [[NSURL alloc] initWithString:buyUrlString];
	[[UIApplication sharedApplication] openURL:buyUrl];
}
Now I am trying to replace the direct URL stored in "buyUrlString" with URL from LinkShare, working off the Apple Tech Q&A QA1629. I believe there is an error in the Apple code. I changed "iTunesLink" in their last line of code to "iTunesURL". Other than that, my current attempt has no errors or warnings, but doesn't do anything either
Code:
- (IBAction) buyButton:(id)sender {
	[self openReferralURL];
}

// Process a LinkShare/TradeDoubler/DGM URL to something iPhone can handle
- (void)openReferralURL:(NSURL *)referralURL {
    NSURL *buyUrl = [[NSURL alloc] initWithString:buyUrlString];
    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:buyUrl] 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];
    // Original code from Apple example uses iTunesLink. Think it is meant to be iTunesURL
    // [[UIApplication sharedApplication] openURL:self.iTunesLink];
}
Thanks for any help you can offer.

PS - For those unfamiliar with LinkShare, there is a nice post called Maximizing your iPhone App development revenue that will help get you started.
DenVog is offline   Reply With Quote
Old 11-06-2009, 02:26 PM   #2 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 624
DenVog is on a distinguished road
Angry

Wow. This is really driving me nuts. I found an example at Epsilon Team that is very similar to the Apple code. If I use a static URL (changing "itunes" to "phobos"), it will open the App Store . If I try to load the same URL from a dictionary, it opens in Safari. When I look at the URL that is being retrieved with NSLog, they look the same to me.
Does NOT work: This opens in Safari, where buyUrlString is pulled from a dictionary
Code:
- (void)openLinkShareURL
{
NSString *referralLink = (@"%@", buyUrlString);
self.iTunesURL = [NSURL URLWithString:referralLink];
NSLog(@"link: %@", referralLink);
NSURLRequest *referralRequest = [NSURLRequest requestWithURL:self.iTunesURL];
NSURLConnection *referralConnection = [[NSURLConnection alloc] initWithRequest:referralRequest delegate:self startImmediately:YES];
[referralConnection release];
}
Does work: I copy and past the URL from the dictionary, so it is hard coded and it works?! WTF?!
Code:
- (void)openLinkShareURL
{
NSString *referralLink =@"http://click.linksynergy.com/myUrl/goesHere";
self.iTunesURL = [NSURL URLWithString:referralLink];
NSURLRequest *referralRequest = [NSURLRequest requestWithURL:self.iTunesURL];
NSURLConnection *referralConnection = [[NSURLConnection alloc] initWithRequest:referralRequest delegate:self startImmediately:YES];
[referralConnection release];
}
I'd really appreciate it if someone can:
  1. Tell me why pulling the same string from a dictionary doesn't work
  2. If changing "itunes" to "phobos" is going to prevent getting credit from LinkShare
Thanks for your help.
DenVog is offline   Reply With Quote
Old 11-06-2009, 08:33 PM   #3 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 624
DenVog is on a distinguished road
Default

I have narrowed this down somewhat, but am still quite puzzled. It seems that whenever a URL is pulled from the dictionary, it is adding extra characters. Any place in the URL where "%25" appears, the code is adding an extra "25". so:
Code:
http%253A%252F%252Fphobos.apple.com%252F
becomes
Code:
http%25253A%25252F%25252Fphobos.apple.com%25252F
Not sure why this is happening, or what should be done to fix it. Have been searching for any encode that might fit this pattern, but am not finding anything. Any insight would be greatly appreciated.
DenVog is offline   Reply With Quote
Old 11-06-2009, 09:21 PM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 89
kiancheong is on a distinguished road
Default

Looks like you caught Apple's mistake. As I noted here, the code provided by Apple has some mistakes, which I took quite some time to catch too.

As to answer your questions:
1) can't help much as I don't know how your dictionary was declared
2) nope, you will still get creditted

fyi, the iPhone and iPod touch looks at the URL and decides whether to open it via Safari or the AppStore application, for this instance, phobos will always open in the AppStore application. when you get your link from the iTunes Link Maker, it will most likely be in "itunes.apple.com" format - just change it...

hope this helps...

p/s: have you tried simulating a failed redirection? my app crashes when it fails to redirect
kiancheong is offline   Reply With Quote
Old 11-07-2009, 07:43 AM   #5 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 624
DenVog is on a distinguished road
Default

Quote:
Originally Posted by kiancheong View Post
As to answer your questions:
1) can't help much as I don't know how your dictionary was declared
Thanks for your response. I created the dictionary within XCode by doing:
File > New File > Other > Property List
I set up the keys in XCode, then pasted my values in from various sources. If I open the plist with a text editor, it shows
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
The URL still look correct in the text editor.
Quote:
Originally Posted by kiancheong View Post
2) nope, you will still get creditted
Great!
Quote:
Originally Posted by kiancheong View Post
p/s: have you tried simulating a failed redirection? my app crashes when it fails to redirect
I have not experienced crashes due to this. It just opens Safari and comes up with a blank page, as the URL is not valid.
DenVog is offline   Reply With Quote
Old 09-12-2011, 07:08 PM   #6 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 1
expertmouser is on a distinguished road
Default

just a note on the apple example code,
i believe it has a bug.

in this line: "self.iTunesURL = [response URL];",
i believe it retains a reference to a non-durable URL,
and indeed, if the code in the article is called repeatedly (eg the user taps a button repeatedly), it crashes when we attempt to use self.iTunesURL.

in my limited testing, this is fixed by changing the line to:
self.iTunesURL = [[response URL] copy];

i'm still filling in gaps in my Objective C understanding,
so my proposed fix may represent a [small] memory leak,
so if you're going to be hitting the code a lot, probably want a different fix.
expertmouser is offline   Reply With Quote
Reply

Bookmarks

Tags
linkshare

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 344
11 members and 333 guests
alexP, ClerurcifeDer, Duncan C, givensur, glenn_sayers, guusleijsten, JmayLive, NetGuru, Punkjumper, whitey99, yys
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:41 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0