Archivi categoria: Xcode

Xcode App Transport Security fix in Xcode 7, and resolve ‘Could not connect to the server’ errors

Apple made a radical decision with iOS 9, disabling all unsecured HTTP traffic from iOS apps, as a part of App Transport Security. This helps in enforcing security best practices, but if you  want to load external content, like arbitrary links, you have to add this value to your app info.plist:

key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

iPhone Dev – Asynchronous image downloader with cache support with an UIImageView category

Here git of Asynchronous image downloader with cache support with an UIImageView category. This library provides a category for UIImageVIew with support for remote images coming from the web.

It provides:

  • An UIImageView category adding web image and cache management to the Cocoa Touch framework
  • An asynchronous image downloader
  • An asynchronous memory + disk image caching with automatic cache expiration handling
  • Animated GIF support
  • WebP format support
  • A background image decompression
  • A guarantee that the same URL won’t be downloaded several times
  • A guarantee that bogus URLs won’t be retried again and again
  • A guarantee that main thread will never be blocked
  • Performances!
  • Use GCD and ARC

https://github.com/rs/SDWebImage

IOS iPhone/iPad – check call service capability of the device

sometimes you need to check the type of device that will use our application in order to identify whether the device is an iphone, ipod or iPad. To check this we can read the [UIDevice currentDevice].model such you are essentially comparing the device name with a hard-coded value. Example

if(![[UIDevice currentDevice].model isEqualToString:@"iPhone"])
{
UIAlertView *alertView = [UIAlertView alloc] initWithTitle:@"Error"
message:@"Call service not avalible on this device"
delegate:self
cancelButtonTitle:@"close"
otherButtonTitles: nil];
[alertView show];
[alertView release];
}

as alternative we can add a control if the device can openURL “tel:xxx-xxxx-xxxx” which is the protocol used to make a call on an iPhone device:

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:RISTOSTREGA_PHONE]]

more in deep we ca use to know exactly the generation of device the class UIDeviceHardware:

UIDeviceHardware *h=[[UIDeviceHardware alloc] init];
[self setDeviceModel:[h platformString]];
[h release];

the class UIDeviceHardware.h:

@interface UIDeviceHardware : NSObject
- (NSString *) platform;
- (NSString *) platformString;
@end

in the implementation file UIDeviceHardware.m:

#include
#include

@implementation UIDeviceHardware

- (NSString *) platform{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine];
free(machine);
return platform;
}

- (NSString *) platformString{
NSString *platform = [self platform];
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
if ([platform isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
if ([platform isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
if ([platform isEqualToString:@"iPod3,1"]) return @"iPod Touch 4G";
if ([platform isEqualToString:@"i386"]) return @"iPhone Simulator";
return platform;
}

@end