UIDevice *device = [[UIDevice alloc] int];
NSString *name = device.name; //获取设备所有者的名称
NSString *model = device.name; //获取设备的类别
NSString *type = device.localizedModel; //获取本地化版本
NSString *systemName = device.systemName; //获取当前运行的系统
NSString *systemVersion = device.systemVersion;//获取当前系统的版本
NSString *identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
(NSString*) createUUID
{
NSString *id = [[NSUserDefaults standardUserDefaults] objectForKey:@"UUID"]; //获取标识为"UUID"的值
if(id == nil)
{
if([[[UIDevice currentDevice] systemVersion] floatValue] > 6.0)
{
NSString *identifierNumber = [[NSUUID UUID] UUIDString]; //ios 6.0 之后可以使用的api
[[NSUserDefaults standardUserDefaults] setObject:identifierNumber forKey:@"UUID"]; //保存为UUID
[[NSUserDefaults standardUserDefaults] synchronize];
}
else{
CFUUIDRef uuid = CFUUIDCreate(NULL);
CFStringRef uuidString = CFUUIDCreateString(NULL, uuid); //ios6.0之前使用的api
NSString *identifierNumber = [NSString stringWithFormat:@"%@", uuidString];
[[NSUserDefaults standardUserDefaults] setObject:identifierNumber forKey:@"UUID"];
[[NSUserDefaults standardUserDefaults] synchronize];
CFRelease(uuidString);
CFRelease(uuid);
}
return [[NSUserDefaults standardUserDefaults] objectForKey@"UUID"];
}
return id;
}
CGRect rect = [[UIScreen mainScreen] bounds];
CGFloat scale = [[UIScreen mainScreen].scale];
CGFloat width = rect.size.width * scale;
CGFloat height = rect.size.height * scale;
#import
#import
创建对象
CCTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [info subscriberCellularProvider];
NSString *mCarrier = [NSString stringWithFormat:@"%@",[carrier carrierName]];
NSString *mConnectType = [[NSString alloc] initWithFormat:@"%@",info.currentRadioAccessTechnology];
CTRadioAccessTechnologyGPRS //介于2G和3G之间,也叫2.5G ,过度技术
CTRadioAccessTechnologyEdge //EDGE为GPRS到第三代移动通信的过渡,EDGE俗称2.75G
CTRadioAccessTechnologyWCDMA
CTRadioAccessTechnologyHSDPA //亦称为3.5G(3?G)
CTRadioAccessTechnologyHSUPA //3G到4G的过度技术
CTRadioAccessTechnologyCDMA1x //3G
CTRadioAccessTechnologyCDMAEVDORev0 //3G标准
CTRadioAccessTechnologyCDMAEVDORevA
CTRadioAccessTechnologyCDMAEVDORevB
CTRadioAccessTechnologyeHRPD //电信使用的一种3G到4G的演进技术, 3.75G
CTRadioAccessTechnologyLTE //接近4G
Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
switch([reach currentReachabilityStatus])
{
case NotReachable: //没有连接上
//do something
break;
case ReachableViaWiFi: //通过wifi连接
//do something
break;
case ReachableViaWWAN: //通过GPRS连接
//do something
break;
default: //未知情况
//do something
break;
}
http://blog.csdn.net/qijianli/article/details/19922653 这个博客还说了其它的方法,不过因为是调用私有API,所以没有采用。(int) getSignalLevel
{
void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony",RTLD_LAZY);//获取库句柄
int (*CTGetSignalStrength)(); //定义一个与将要获取的函数匹配的函数指针
CTGetSignalStrength = (int(*)())dlsym(libHandle,"CTGetSignalStrength"); //获取指定名称的函数
if(CTGetSignalStrength == NULL)
return -1;
else{
int level = CTGetSignalStrength();
dlclose(libHandle); //切记关闭库
return level
}
}
AudioServicesPlaySystemSound ( kSystemSoundID_Vibrate) ;
但是貌似这个不支持传入震动时间和模式,自己去控制吧。@implementation BatterMonitor
//获取电池当前的状态,共有4种状态
-(NSString*) getBatteryState {
UIDevice *device = [UIDevice currentDevice];
if (device.batteryState == UIDeviceBatteryStateUnknown) {
return @"UnKnow";
}else if (device.batteryState == UIDeviceBatteryStateUnplugged){
return @"Unplugged";
}else if (device.batteryState == UIDeviceBatteryStateCharging){
return @"Charging";
}else if (device.batteryState == UIDeviceBatteryStateFull){
return @"Full";
}
return nil;
}
//获取电量的等级,0.00~1.00
-(float) getBatteryLevel {
return [UIDevice currentDevice].batteryLevel;
}
-(void) getBatteryInfo
{
NSString *state = getBatteryState();
float level = getBatteryLevel()*100.0;
//yourControlFunc(state, level); //写自己要实现的获取电量信息后怎么处理
}
//打开对电量和电池状态的监控,类似定时器的功能
-(void) didLoad
{
[[UIDevice currentDevice] setBatteryMonitoringEnable:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getBatteryInfo:) name:UIDeviceBatteryStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getBatteryInfo:) name:UIDeviceBatteryLevelDidChangeNotification object:nil];
[NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(getBatteryInfo:) userInfo:nil repeats:YES];
}
@end
NSString *url = @"www.apple.com"
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
打开另一个app还是可以通过openURL来实现。但是要分两种情况。第一种是启动内置的应用,一般的电话,浏览器,短信和
邮件可以直接调用并添加参数,譬如
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://10086"]];
Step1. 右键,选择“Add Row”
Step2. Key值选择“URL types”
Step3. 打开“Item 0″,然后为该key增加一个URL identifier。可以是任何值,但建议用“反域名”(例如 “com.fcplayer.testHello”)。
Step4. 在“Item 0”下再加一行。
Step5. 选择“URL Schemes” 作为Key。
Step6. 输入你的URL协议名 (例如“testHello://” 应写做“testHello”)。如果有必要,你可以在这里加入多个协议。
其实在打开的时候只需要URL Schemes即可,URL identifier是可选项。如果需要传送参数,可以在URL Schemes://添加你的参数,格式和网页开发的传递参数差不多。(又或者URL Schemes://URL identifier@添加的参数)关键是要和接收参数方定义好处理的方式。然后在需要打开的地方添加代码:
NSString *url = @"URL Schemes的路径"
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];