diff --git a/clients/ios/Classes/AddSiteViewController.m b/clients/ios/Classes/AddSiteViewController.m index 867e292f5..02bdbb06b 100644 --- a/clients/ios/Classes/AddSiteViewController.m +++ b/clients/ios/Classes/AddSiteViewController.m @@ -13,7 +13,6 @@ #import "NBContainerViewController.h" #import "MenuViewController.h" #import "SBJson4.h" -#import "Base64.h" @interface AddSiteViewController() @@ -413,7 +412,7 @@ NSString *favicon = [result objectForKey:@"favicon"]; UIImage *faviconImage; if ((NSNull *)favicon != [NSNull null] && [favicon length] > 0) { - NSData *imageData = [NSData dataWithBase64EncodedString:favicon]; + NSData *imageData = [[NSData alloc] initWithBase64EncodedString:favicon options:NSDataBase64DecodingIgnoreUnknownCharacters]; faviconImage = [UIImage imageWithData:imageData]; } else { faviconImage = [UIImage imageNamed:@"world.png"]; diff --git a/clients/ios/Classes/FeedDetailViewController.m b/clients/ios/Classes/FeedDetailViewController.m index 32006773b..eef98450e 100644 --- a/clients/ios/Classes/FeedDetailViewController.m +++ b/clients/ios/Classes/FeedDetailViewController.m @@ -17,7 +17,6 @@ #import "StoryPageControl.h" #import "NSString+HTML.h" #import "MBProgressHUD.h" -#import "Base64.h" #import "SBJson4.h" #import "NSObject+SBJSON.h" #import "StringHelper.h" @@ -2414,7 +2413,7 @@ didEndSwipingSwipingWithState:(MCSwipeTableViewCellState)state NSString *favicon = [feed objectForKey:@"favicon"]; if ((NSNull *)favicon != [NSNull null] && [favicon length] > 0) { - NSData *imageData = [NSData dataWithBase64EncodedString:favicon]; + NSData *imageData = [[NSData alloc] initWithBase64EncodedString:favicon options:NSDataBase64DecodingIgnoreUnknownCharacters]; UIImage *faviconImage = [UIImage imageWithData:imageData]; [appDelegate saveFavicon:faviconImage feedId:feed_id]; } diff --git a/clients/ios/Classes/FirstTimeUserAddSitesViewController.m b/clients/ios/Classes/FirstTimeUserAddSitesViewController.m index 9aa2dcf9f..5c9561504 100644 --- a/clients/ios/Classes/FirstTimeUserAddSitesViewController.m +++ b/clients/ios/Classes/FirstTimeUserAddSitesViewController.m @@ -12,7 +12,6 @@ #import "AuthorizeServicesViewController.h" #import "NewsBlurViewController.h" #import "SiteCell.h" -#import "Base64.h" @interface FirstTimeUserAddSitesViewController() @@ -394,7 +393,7 @@ // favicon NSString *faviconStr = [NSString stringWithFormat:@"%@", [feed valueForKey:@"favicon"]]; - NSData *imageData = [NSData dataWithBase64EncodedString:faviconStr]; + NSData *imageData = [[NSData alloc] initWithBase64EncodedString:faviconStr options:NSDataBase64DecodingIgnoreUnknownCharacters]; UIImage *faviconImage = [UIImage imageWithData:imageData]; diff --git a/clients/ios/Classes/NewsBlurViewController.m b/clients/ios/Classes/NewsBlurViewController.m index f64fa6e22..df813df36 100644 --- a/clients/ios/Classes/NewsBlurViewController.m +++ b/clients/ios/Classes/NewsBlurViewController.m @@ -21,7 +21,6 @@ #import "StoryDetailViewController.h" #import "StoryPageControl.h" #import "MBProgressHUD.h" -#import "Base64.h" #import "SBJson4.h" #import "NSObject+SBJSON.h" #import "NBNotifier.h" @@ -1826,7 +1825,8 @@ heightForHeaderInSection:(NSInteger)section { if (![appDelegate.dictFeeds objectForKey:feed_id]) continue; NSString *favicon = [results objectForKey:feed_id]; if ((NSNull *)favicon != [NSNull null] && [favicon length] > 0) { - NSData *imageData = [NSData dataWithBase64EncodedString:favicon]; + NSData *imageData = [[NSData alloc] initWithBase64EncodedString:favicon options:NSDataBase64DecodingIgnoreUnknownCharacters]; +// NSData *imageData = [NSData dataWithBase64EncodedString:favicon]; UIImage *faviconImage = [UIImage imageWithData:imageData]; [appDelegate saveFavicon:faviconImage feedId:feed_id]; } diff --git a/clients/ios/Classes/StoryDetailViewController.m b/clients/ios/Classes/StoryDetailViewController.m index 8a25e40be..944653e46 100644 --- a/clients/ios/Classes/StoryDetailViewController.m +++ b/clients/ios/Classes/StoryDetailViewController.m @@ -16,7 +16,6 @@ #import "UserProfileViewController.h" #import "ShareViewController.h" #import "StoryPageControl.h" -#import "Base64.h" #import "Utilities.h" #import "NSString+HTML.h" #import "NBContainerViewController.h" diff --git a/clients/ios/Classes/StoryPageControl.m b/clients/ios/Classes/StoryPageControl.m index c1fcd6243..22f860ae9 100644 --- a/clients/ios/Classes/StoryPageControl.m +++ b/clients/ios/Classes/StoryPageControl.m @@ -14,7 +14,6 @@ #import "FontSettingsViewController.h" #import "UserProfileViewController.h" #import "ShareViewController.h" -#import "Base64.h" #import "Utilities.h" #import "NSString+HTML.h" #import "NBContainerViewController.h" diff --git a/clients/ios/Classes/TrainerViewController.m b/clients/ios/Classes/TrainerViewController.m index b787ecc03..fbedd1204 100644 --- a/clients/ios/Classes/TrainerViewController.m +++ b/clients/ios/Classes/TrainerViewController.m @@ -10,7 +10,6 @@ #import "NBContainerViewController.h" #import "StringHelper.h" #import "Utilities.h" -#import "Base64.h" #import "AFNetworking.h" #import "StoriesCollection.h" @@ -422,7 +421,7 @@ UIImage *favicon = [appDelegate getFavicon:feedId]; NSData *faviconData = UIImagePNGRepresentation(favicon); NSString *feedImageUrl = [NSString stringWithFormat:@"data:image/png;charset=utf-8;base64,%@", - [faviconData base64Encoding]]; + [faviconData base64EncodedDataWithOptions:NSDataBase64Encoding64CharacterLineLength]]; NSString *publisherTitle = [NSString stringWithFormat:@" %@", feedImageUrl, feedTitle]; NSString *storyPublisher = [NSString stringWithFormat:@"
" diff --git a/clients/ios/NewsBlur.xcodeproj/project.pbxproj b/clients/ios/NewsBlur.xcodeproj/project.pbxproj index 4e35f0662..c6ac555f3 100755 --- a/clients/ios/NewsBlur.xcodeproj/project.pbxproj +++ b/clients/ios/NewsBlur.xcodeproj/project.pbxproj @@ -146,7 +146,6 @@ 43A4BAE915C866FA00F3B8D4 /* popoverBgSimple.png in Resources */ = {isa = PBXBuildFile; fileRef = 43A4BADA15C866FA00F3B8D4 /* popoverBgSimple.png */; }; 43A4BAEB15C893E300F3B8D4 /* FriendsListViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 43A4BAEA15C893E300F3B8D4 /* FriendsListViewController.xib */; }; 43A4C3D715B00966008787B5 /* ABTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A4C3BA15B00966008787B5 /* ABTableViewCell.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - 43A4C3D815B00966008787B5 /* Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A4C3BC15B00966008787B5 /* Base64.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; 43A4C3DA15B00966008787B5 /* GTMNString+HTML.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A4C3C015B00966008787B5 /* GTMNString+HTML.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; 43A4C3DC15B00966008787B5 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A4C3C215B00966008787B5 /* main.m */; }; 43A4C3DD15B00966008787B5 /* MBProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = 43A4C3C415B00966008787B5 /* MBProgressHUD.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; @@ -762,8 +761,6 @@ 43A4BAEA15C893E300F3B8D4 /* FriendsListViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FriendsListViewController.xib; sourceTree = ""; }; 43A4C3B915B00966008787B5 /* ABTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ABTableViewCell.h; path = "Other Sources/ABTableViewCell.h"; sourceTree = ""; }; 43A4C3BA15B00966008787B5 /* ABTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ABTableViewCell.m; path = "Other Sources/ABTableViewCell.m"; sourceTree = ""; }; - 43A4C3BB15B00966008787B5 /* Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Base64.h; path = "Other Sources/Base64.h"; sourceTree = ""; }; - 43A4C3BC15B00966008787B5 /* Base64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Base64.m; path = "Other Sources/Base64.m"; sourceTree = ""; }; 43A4C3BE15B00966008787B5 /* GTMDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GTMDefines.h; path = "Other Sources/GTMDefines.h"; sourceTree = ""; }; 43A4C3BF15B00966008787B5 /* GTMNString+HTML.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "GTMNString+HTML.h"; path = "Other Sources/GTMNString+HTML.h"; sourceTree = ""; }; 43A4C3C015B00966008787B5 /* GTMNString+HTML.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "GTMNString+HTML.m"; path = "Other Sources/GTMNString+HTML.m"; sourceTree = ""; }; @@ -1527,8 +1524,6 @@ 43A4C3E615B0099B008787B5 /* NewsBlur_Prefix.pch */, 43A4C3B915B00966008787B5 /* ABTableViewCell.h */, 43A4C3BA15B00966008787B5 /* ABTableViewCell.m */, - 43A4C3BB15B00966008787B5 /* Base64.h */, - 43A4C3BC15B00966008787B5 /* Base64.m */, 43A4C3BE15B00966008787B5 /* GTMDefines.h */, 43A4C3BF15B00966008787B5 /* GTMNString+HTML.h */, 43A4C3C015B00966008787B5 /* GTMNString+HTML.m */, @@ -3142,7 +3137,6 @@ 437F976F15AE21290007136B /* ActivityModule.m in Sources */, 437F977215AE70E30007136B /* InteractionsModule.m in Sources */, 43A4C3D715B00966008787B5 /* ABTableViewCell.m in Sources */, - 43A4C3D815B00966008787B5 /* Base64.m in Sources */, 43A4C3DA15B00966008787B5 /* GTMNString+HTML.m in Sources */, 43A4C3DC15B00966008787B5 /* main.m in Sources */, 43A4C3DD15B00966008787B5 /* MBProgressHUD.m in Sources */, diff --git a/clients/ios/Other Sources/Base64.h b/clients/ios/Other Sources/Base64.h deleted file mode 100644 index 883f3c895..000000000 --- a/clients/ios/Other Sources/Base64.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// Base64.h -// NewsBlur -// -// Created by Samuel Clay on 8/3/11. -// Copyright 2011 NewsBlur. All rights reserved. -// - - - -@interface NSData (MBBase64) - -+ (id)dataWithBase64EncodedString:(NSString *)string; // Padding '=' characters are optional. Whitespace is ignored. -- (NSString *)base64Encoding; -@end diff --git a/clients/ios/Other Sources/Base64.m b/clients/ios/Other Sources/Base64.m deleted file mode 100644 index 994eb300e..000000000 --- a/clients/ios/Other Sources/Base64.m +++ /dev/null @@ -1,111 +0,0 @@ -#include "Base64.h" - -static const char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - - -@implementation NSData (MBBase64) - -+ (id)dataWithBase64EncodedString:(NSString *)string; -{ - if (string == nil) - [NSException raise:NSInvalidArgumentException format:@""]; - if ([string length] == 0) - return [NSData data]; - - static char *decodingTable = NULL; - if (decodingTable == NULL) - { - decodingTable = malloc(256); - if (decodingTable == NULL) - return nil; - memset(decodingTable, CHAR_MAX, 256); - NSUInteger i; - for (i = 0; i < 64; i++) - decodingTable[(short)encodingTable[i]] = i; - } - - const char *characters = [string cStringUsingEncoding:NSASCIIStringEncoding]; - if (characters == NULL) // Not an ASCII string! - return nil; - char *bytes = malloc((([string length] + 3) / 4) * 3); - if (bytes == NULL) - return nil; - NSUInteger length = 0; - - NSUInteger i = 0; - while (YES) - { - char buffer[4]; - short bufferLength; - for (bufferLength = 0; bufferLength < 4; i++) - { - if (characters[i] == '\0') - break; - if (isspace(characters[i]) || characters[i] == '=') - continue; - buffer[bufferLength] = decodingTable[(short)characters[i]]; - if (buffer[bufferLength++] == CHAR_MAX) // Illegal character! - { - free(bytes); - return nil; - } - } - - if (bufferLength == 0) - break; - if (bufferLength == 1) // At least two characters are needed to produce one byte! - { - free(bytes); - return nil; - } - - // Decode the characters in the buffer to bytes. - bytes[length++] = (buffer[0] << 2) | (buffer[1] >> 4); - if (bufferLength > 2) - bytes[length++] = (buffer[1] << 4) | (buffer[2] >> 2); - if (bufferLength > 3) - bytes[length++] = (buffer[2] << 6) | buffer[3]; - } - - char *temp = realloc(bytes, length); - - if (temp) { - return [NSData dataWithBytesNoCopy:bytes length:length]; - } else { - return nil; - } -} - -- (NSString *)base64Encoding; -{ - if ([self length] == 0) - return @""; - - char *characters = malloc((([self length] + 2) / 3) * 4); - if (characters == NULL) - return nil; - NSUInteger length = 0; - - NSUInteger i = 0; - while (i < [self length]) - { - char buffer[3] = {0,0,0}; - short bufferLength = 0; - while (bufferLength < 3 && i < [self length]) - buffer[bufferLength++] = ((char *)[self bytes])[i++]; - - // Encode the bytes in the buffer to four characters, including padding "=" characters if necessary. - characters[length++] = encodingTable[(buffer[0] & 0xFC) >> 2]; - characters[length++] = encodingTable[((buffer[0] & 0x03) << 4) | ((buffer[1] & 0xF0) >> 4)]; - if (bufferLength > 1) - characters[length++] = encodingTable[((buffer[1] & 0x0F) << 2) | ((buffer[2] & 0xC0) >> 6)]; - else characters[length++] = '='; - if (bufferLength > 2) - characters[length++] = encodingTable[buffer[2] & 0x3F]; - else characters[length++] = '='; - } - - return [[[NSString alloc] initWithBytesNoCopy:characters length:length encoding:NSASCIIStringEncoding freeWhenDone:YES] autorelease]; -} - -@end