Objective-C
共 3 篇文章
扩展UIDevice来监测网络连接
《The iPhone Developer's Cookbook》 没什么好说的,直接上代码: 1、UIDevice+Reachability.h: #import <UIKit/UIKit.h> @interface UIDevice (Reachability) + (BOOL) networkAvailable; + (BOOL) activeWLAN; + (BOOL) activeWWAN; @end 2、UIDevice+Reachability.m: #import <SystemConfiguration/SystemConfiguration.h> #include <ar…
2013-11-07 17:40 · iOS · Objective-C
判断网络是否连接
iOS开发中判断网络连接的操作步骤如下: 1、添加framework,SystemConfiguration.framework; 2、倒入文件: #import <SystemConfiguration/SystemConfiguration.h> #include <netdb.h> 3、判断方法: - (BOOL) connectedToNetwork { // Create zero addy struct sockaddr_in zeroAddress; bzero(&zeroAddress, sizeof(zeroAddress)); zeroAddress.sin_len = …
2013-11-07 17:32 · iOS · Objective-C
Objective-C 创建单例
程序开发(Objective-C)中,经常要用到单例,其创建代码如下: static Car *sharedInstance = nil; #pragma mark Single instance + (Car *)sharedInstance { if (!sharedInstance) { sharedInstance = [[self alloc] init]; } return sharedInstance; } + (id)allocWithZone:(struct _NSZone *)zone { @synchronized(self) { if (sharedInstance …
2013-11-07 12:14 · Objective-C · 单例