Getting Safe[r] Short links in your iOS App

UPDATE: This post has been updated here.

Traditionally known for their bloat ware anti-virus, McAfee has decided to get into the short-URL service with their new beta program of Mcaf.ee. Many security experts have agreed that using URL shortening services is a great way to masquerade malicious sites and to dupe victims into visiting them. McAfee’s new service applies their site reputation scoring to the links you submit. Sites with a “Red” level will be blocked from being displayed and a banner is displayed at the top. For more details about how they rank sites, visit their documentation site: https://community.mcafee.com/docs/DOC-1791 or http://mcaf.ee/a8fb4. This is a way to add a little more trust to the links that you share.

McAfee URL Shortener Screen Shot

Now, say you have an iOS app that has Twitter integration of some sort and you want to share shortened links in a more safe manner by using Mcafee’s short-URL service. It’s very simple to do so in code.


//First setup the URLs
NSURL *urlToShorten=[NSURL URLWithString:@"http://www.shawnsbits.com"];
NSURL *mcafeeShortener=[NSURL URLWithString:[NSString stringWithFormat:@"http://mcaf.ee/CREATE?v=%@", urlToShorten]];

//Get the resulting web page
NSString *mcafeeResults=[NSString stringWithContentsOfURL:mcafeeShortener encoding:NSStringEncodingConversionAllowLossy error:nil];

//Start to parse the result by finding the generated link
NSRange urlRange=[mcafeeResults rangeOfString:@"is mapped to <a href=""];

NSRange spanRange=urlRange;
spanRange.length=spanRange.length+50;

NSRange urlEndRange=[mcafeeResults rangeOfString:@"">" options:NSLiteralSearch range:spanRange];

/The range of the shortened link is in between the two ranges
spanRange.location=urlRange.location+urlRange.length;
spanRange.length=urlEndRange.location-spanRange.location;

NSString *mcafeeShortenedURLString=[mcafeeResults substringWithRange:spanRange];
NSLog(@"MCafee URL: %@", mcafeeShortenedURLString);

No comments yet.

Leave a Reply