【1】 推断是否是横向屏:

BOOL b=UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation);

获取设备uniqueIdentifier :

[UIDevice currentDevice].uniqueIdentifier;

但在ios5中,它已被废弃。

http://kensou.blog.51cto.com/3495587/655083

[[UIDevice currentDevice] systemName];
[[UIDevice currentDevice] systemVersion];//os version
[[UIDevice currentDevice] uniqueIdentifier];
[[UIDevice currentDevice] model];
[[UIDevice currentDevice] name];

真机上结果:

System Name: iPhone OS

System Version: 4.2.1

Unique ID: 9b5ded78d5fa0ac96250f8b4af0e46f40b96ea6d

Model: iPhone

Name: “wwk”的 iPhone

模拟器上结果:

System Name: iPhone OS

System Version: 4.2

Unique ID: 21FFE0FF-429B-5D0B-96D2-EADCA3203260

Model: iPhone Simulator

Name: iPhone Simulator

uniqueIdentifier:iPhone通过。向几个硬件标识符和设备序列号应用内部散列算法。而生成这一标识符。

【2】电池事件通知及电池状态:电池水平是一个浮点值,从0.0全然放电,到1.0全然充满。

[NSLog:@"Battery level: %0.2f%", [[UIDevice currentDevice] batteryLevel] * 100];
NSArray *stateArray = [NSArray arrayWithObjects: @"Unknown", @"not plugged into a charging source", @"charging", @"full", nil];
[NSLog:@"Battery state: %@", [stateArray objectAtIndex:[[UIDevice currentDevice] batteryState]]];

获得很多其它设备信息:使用sysctlbyname(),sysctl()标准unix函数。

在sys/sysctl.h中提供了一些设备信息常量。要注意先要#include <sys/socket.h>。

详细的參考《秘籍2》14.3又一次获得很多其它设备信息。

hw.machine的值,第一代iPhone为(iPhone1,1)。iPhone3g为(iPhone1,2)。iPhone3gs为(iPhone2,1),模拟器上为x86_64。

【3】.传感器。

启用接近传感器后,它检測前方是否存在一个大型物体,假设有。它会关闭屏幕,并发出一般性通知。当障碍物移走后,会又一次打开屏幕。这能够防止在通知过程中,误用耳朵触碰button。

还要防止一些保护套会影响传感器工作。

  [UIDevice currentDevice].proximityMonitoringEnabled=YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleStateChange:) name:@"UIDeviceProximityStateDidChangeNotification" object:nil];

【4】加速度。

在測量速度上,iPhone提供了3个板载传感器。它们沿iPhone垂直坐标轴的3个方向xyz測量加速度。这些值表示影响iPhone的力。

   [[UIAccelerometer sharedAccelerometer] setDelegate:self];//UIAccelerometerDelegate
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
float xx = -[acceleration x];
float yy = [acceleration y];
float angle = atan2(yy, xx);
[arrow setTransform:CGAffineTransformMakeRotation(angle)];
}

【5】检測设备方向:横线或纵向。

  [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; // not actually required but a good idea in case Apple changes this
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
// 在viewController中重写shouldAutorotateToInterfaceOrientation
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) anOrientation
{
return (anOrientation == UIDeviceOrientationPortrait ||
anOrientation == UIDeviceOrientationLandscapeRight ||
anOrientation == UIDeviceOrientationLandscapeLeft ||);
// iPhone不建议使用UIDeviceOrientationPortraitUpsizeDown
} - (void) orientationChanged: (id) sender
{
NSLog(@"Orientation changed to %@", [UIDevice currentDevice].orientationString);//当前设备方向
}
// 两个内置的宏辅助推断方向
UIDeviceOrientationIsPortrait(anOrientation)
UIDeviceOrientationIsLandscape(anOrientation)

【6】摇晃检測  ShakeDetection。

响应链:响应链提供了层级对象,一个事件若被起始处的对象接收。它不会再被向下传递。否则,继续向下传递。

对象一般是通过[self becomeFirstResponder];声明自身为第一响应者。[self resignFirstResponder];声明退出第一响应者。

第一响应者接收全部运动和触摸事件。

  - (BOOL)canBecomeFirstResponder {return YES;}

有例如以下3个运动回调函数能够被覆盖,它们定义在UIResponder中:

 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event

【7】磁盘空间

  NSFileManager *fm = [NSFileManager defaultManager];
NSDictionary *fattributes = [fm fileSystemAttributesAtPath:NSHomeDirectory()];
System space:[[fattributes objectForKey:NSFileSystemSize] longLongValue];
System free space: [[fattributes objectForKey:NSFileSystemFreeSize] longLongValue];

【8】iTunes通过在info.plist中列出的设备功能列表。确定一个程序能否够下载到指定设备中并正常执行。

【9】在AVAILABILITY.h文件里有版本号宏定义,比如:__IPHONE_4_2

这个是os version还是sdk version,或者它们是同样的?

http://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/Availability.h

【10】

NSString* udid=[[UIDevice currentDevice] uniqueIdentifier];
return udid;

【11】

//改为在最上层使用了一层button来响应点击事件
/*
else
{
NSString* systemVersion=[[UIDevice currentDevice] systemVersion];
float floatVersion=[systemVersion floatValue];
NSLog(@"systemVersion:%@,floatVersion:%f",systemVersion,floatVersion);
if(floatVersion<5.0)
{
//in ios5。每层UIView均会响应touchesEnded,所以ios5不用这里向上调了。
ret=[(ViewGroupWrap*)iSuperViewWrap handleTouch];
}
}
*/

【12】coding区分iphone ipod & ipad 的几种方法

(1)使用  UI_USER_INTERFACE_IDIOM() 进行区分

UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad    //ipad
UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone //iPhone

(2)使用 UIDevice.model 进行区分

NSString *deviceType = [UIDevice currentDevice].model;

    if([deviceType isEqualToString:@"iPhone"]) {
//iPhone
}
else if([deviceType isEqualToString:@"iPod touch"]) {
//iPod Touch
}
else {
//iPad
}

(3)使用系统的一个函数sysctlbyname 来获取设备名称

- (NSString *) platformString
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
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:@"iPhone3,1"]) return @"iPhone 4";
if ([platform isEqualToString:@"iPhone3,3"]) return @"Verizon iPhone 4";
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 3G";
if ([platform isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
if ([platform isEqualToString:@"iPad1,1"]) return @"iPad";
if ([platform isEqualToString:@"iPad2,1"]) return @"iPad 2 (WiFi)";
if ([platform isEqualToString:@"iPad2,2"]) return @"iPad 2 (GSM)";
if ([platform isEqualToString:@"iPad2,3"]) return @"iPad 2 (CDMA)";
if ([platform isEqualToString:@"i386"]) return @"Simulator";
return @"";
}

參考   http://hi.baidu.com/songxiaoweiss/blog/item/c78162f869fc148c58ee9028.html

【13】关于获取IMSI号

CoreTelephony.framework。

头文件内容

extern NSString* c*****t kCTSMSMessageReceivedNotification;
extern NSString* c*****t kCTSMSMessageReplaceReceivedNotification;
extern NSString* c*****t kCTSIMSupportSIMStatusNotInserted;
extern NSString* c*****t kCTSIMSupportSIMStatusReady;
id CTTelephonyCenterGetDefault(void);
void CTTelephonyCenterAddObserver(id,id,CFNotificationCallback,NSString*,void*,int);
void CTTelephonyCenterRemoveObserver(id,id,NSString*,void*);
int CTSMSMessageGetUnreadCount(void);
int CTSMSMessageGetRecordIdentifier(void * msg);
NSString * CTSIMSupportGetSIMStatus(); //获取sim卡状态。kCTSIMSupportSIMStatusNotInserted表示没有sim卡
NSString * CTSIMSupportCopyMobileSubscriberIdentity(); //获取imsi号码
id CTSMSMessageCreate(void* unknow/*always 0*/,NSString* number,NSString* text);
void * CTSMSMessageCreateReply(void* unknow/*always 0*/,void * forwardTo,NSString* text);
void* CTSMSMessageSend(id server,id msg);
NSString *CTSMSMessageCopyAddress(void *, void *);
NSString *CTSMSMessageCopyText(void *, void *);

调用CTSIMSupportCopyMobileSubscriberIdentity能成功获取到IMSI号

用performSelector来逃过苹果的检查

【iOS开发系列】UIDevice设备信息的更多相关文章

  1. [转载]iOS开发:获取设备信息

    开发iOS平台的应用的时候,可以获取iOS设备的设备信息,包括设备的名称,设备的机型,设备的iOS版本等等.设备信息主要来自 UIDevice 类. UIDevice *currentDevice = ...

  2. iOS开发系列--通知与消息机制

    概述 在多数移动应用中任何时候都只能有一个应用程序处于活跃状态,如果其他应用此刻发生了一些用户感兴趣的那么通过通知机制就可以告诉用户此时发生的事情.iOS中通知机制又叫消息机制,其包括两类:一类是本地 ...

  3. iOS开发系列--数据存取

    概览 在iOS开发中数据存储的方式可以归纳为两类:一类是存储为文件,另一类是存储到数据库.例如前面IOS开发系列-Objective-C之Foundation框架的文章中提到归档.plist文件存储, ...

  4. iOS开发系列--网络开发

    概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博.微信等,这些应用本身可能采用iOS开发,但是所有的数据支撑都是基于后台网络服务器的.如今,网络编程越来越普遍,孤立的应用通常是没有生命力 ...

  5. 【转】iOS开发系列--数据存取

    原文: http://www.cnblogs.com/kenshincui/p/4077833.html#SQLite 概览 在iOS开发中数据存储的方式可以归纳为两类:一类是存储为文件,另一类是存储 ...

  6. iOS开发系列--通知与消息机制--转

    来自:http://www.cocoachina.com/ios/20150318/11364.html 概述 在多数移动应用中任何时候都只能有一个应用程序处于活跃状态,如果其他应用此刻发生了一些用户 ...

  7. iOS开发系列之app的一天

    本文主要讲述我对 iOS 开发的一些理解,希望能通过 app 从启动到退出,将一些的知识整合起来,形成一条知识链,目前涉及到的知识点有 runloop.runtime.文件存储.界面布局.离线推送.内 ...

  8. iOS开发系列--App扩展开发

    概述 从iOS 8 开始Apple引入了扩展(Extension)用于增强系统应用服务和应用之间的交互.它的出现让自定义键盘.系统分享集成等这些依靠系统服务的开发变成了可能.WWDC 2016上众多更 ...

  9. iOS开发系列--Swift进阶

    概述 上一篇文章<iOS开发系列--Swift语言>中对Swift的语法特点以及它和C.ObjC等其他语言的用法区别进行了介绍.当然,这只是Swift的入门基础,但是仅仅了解这些对于使用S ...

  10. iOS开发系列--Swift语言

    概述 Swift是苹果2014年推出的全新的编程语言,它继承了C语言.ObjC的特性,且克服了C语言的兼容性问题.Swift发展过程中不仅保留了ObjC很多语法特性,它也借鉴了多种现代化语言的特点,在 ...

随机推荐

  1. Unsupported major.minor version 52.0 (unable to load class XXX

    java项目构建从高版本JDK改为低版本JDK报错.这是再次编译时使用的JDK版本比你原来编译的版本低所导致的. 转自:http://blog.csdn.net/zixiao217 maven项目在服 ...

  2. Spring整合JUnit4测试使用注解引入多个配置文件

    转自:https://kanpiaoxue.iteye.com/blog/2151903 我们使用spring写junit单测的时候,有的时候我们的spring配置文件只有一个.我们在类的注释上面会这 ...

  3. VM-安装MAC系统

    搜了下论坛没有这个教程,继续搬运一波,这次教的是用VM15安装Mac OS10.14懒人版VMware安装Windows和Linux比较类似,相对于今天要安装的MAC OS来说过程也比较简单.官方原版 ...

  4. oracle scott趣事

    Oracle里面是scott是个什么用户呢? 这个就要追朔到Oracle的创业阶段了, 1977年6月,埃里森,Bob Miner和Ed Oates在硅谷共同创办了一家名为软件开发实验室(Softwa ...

  5. 1.Ventuz 介绍

    Ventoz能做什么? Ventuz是一款实时图文包装内容创作.制作和播出控制软件.Ventuz专注于高端视听内容的制作,包括交互展示和大型活动.视频墙.广播电视在线包装及演播室舞台及灯光控制等领域. ...

  6. javascript 公历与农历相互转换工具类

    /** * 公历[1900-1-31,2100-12-31]时间区间内的公历.农历互转 * @charset UTF-8 * @Author Jea杨(JJonline@JJonline.Cn) * ...

  7. 1350 Taxi Cab Scheme DAG最小路径覆盖

    对于什么是DAG最小路径覆盖以及解题方法在我的另外的博客已经有了.http://www.cnblogs.com/Potato-lover/p/3980470.html 此题的题意: 公交车(出租车)车 ...

  8. UWP Tiles

    1.我们建议安装通知库 NuGet 程序包 详细内容 2.我们建议安装NotificationsVisualizerLibrary 这是 The official NotificationsVisua ...

  9. QT4.8界面设计(MSVC2010X)

    1.C++ IDE设计 MFC这种半死不活的windows C++平台已经被抛弃,很无奈.转向Qt的C++还是不错的选择. QT的QML才是最新的亮点,可惜没有时间经历这些东西了. 2.程序代码 2. ...

  10. layui table 时间戳

    , { field: , title: '时间', templet: '<div>{{ laytpl.toDateString(d) }}</div>' }, 或者 , { f ...