获取IOS 设备基本信息

原地址:http://www.cnblogs.com/U-tansuo/p/ios_basis_info.html

1、获取设备类型  (Iphone/ipad 几?)

#import "sys/utsname.h"

-(NSString*)getDeviceVersion
{
    struct utsname
systemInfo;
    uname(&systemInfo);
   
NSString *deviceString = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
    return
deviceString;
}

2、获取系统时间

NSDate* date = [NSDate
date];  
    NSDateFormatter* formatter =
[[[NSDateFormatter alloc] init] autorelease];
    [formatter
setDateFormat:@"yyyy-MM-dd HH:MM:SS"];
    [formatter
stringFromDate:date];

3、获取应用版本 手机系统版本信息

UIDevice* uiDevice = [UIDevice
currentDevice];  
    NSBundle* nsBundle = [NSBundle
mainBundle];
    NSDictionary *infoDictionary = [nsBundle
infoDictionary];
    NSString* crashInfo = [NSString
stringWithFormat:@"Identifier:%@\nVersion:%@\nOS
Version:%@     %@\nDate/Time:%@\nHardware
Model:%@",
                       
[nsBundle
bundleIdentifier],
                       
[infoDictionary
objectForKey:@"CFBundleVersion"],
                       
[uiDevice
systemName],
                       
[uiDevice
systemVersion],
                       
[self
GetOnlyTime],
                       
[self deviceString] ];

4、获取应用程序目录

NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask,
YES);
    NSString *cacheDir = [paths objectAtIndex: 0];

5、创建应用程序内部文件夹

NSFileManager *fm = [NSFileManager
defaultManager];
        NSDictionary
*attributes = [NSDictionary dictionaryWithObject: [NSNumber
numberWithUnsignedLong: 0755] forKey:
NSFilePosixPermissions];
        if(![fm
fileExistsAtPath:"文件路径"]){
          
 
            [fm
createDirectoryAtPath:"文件路径"withIntermediateDirectories:YES
attributes:attributes error:NULL];
       
}

6、获取某个文件夹下所有文件 及删除以某后缀名结尾文件

NSFileManager *fm = [NSFileManager
defaultManager];
    NSArray *contents = [fm
contentsOfDirectoryAtPath:path error:NULL];
    NSEnumerator
*e = [contents objectEnumerator];
    NSString
*filename;
    while ((filename = [e nextObject]))
{
        NSLog(@"file Name =
%@",filename);
        if ([[filename
pathExtension] isEqualToString:@"txt"]||[[filename pathExtension]
isEqualToString:@"plcrash"]) { 
        
  [path
stringByAppendingPathComponent:filename];
       

    }

获取IOS 设备基本信息,布布扣,bubuko.com

时间: 2024-08-08 22:08:51

获取IOS 设备基本信息的相关文章

远程获取iOS设备的屏幕截图

一个远程获取iOS设备屏幕的例子,Client采用TCP连接iOS设备的2115端口,然后读取PNG格式的数据流. +VSRemoteScreen.h +VSRemoteScreen.m 添加到你的iOS项目中,然后在App启动时调用startScreenServer函数. +client.php client示例文件 [1].[代码] RemoteScreen 跳至 [1] [2] ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

获取iOS设备型号的方法总结

三种常用的办法获取iOS设备的型号: 1. [UIDevice currentDevice].model (推荐): 2. uname(struct utsname *name) ,使用此函数需要#include : 3.sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen) ,使用此函数需要#include ,#include: 推荐使用第一种方法,为最上层的API,在项目开发

获取iOS设备唯一标识

[获取iOS设备唯一标识] 1.已禁用-[UIDevice uniqueIdentifier] 苹果总是把用户的隐私看的很重要.-[UIDevice uniqueIdentifier]在iOS5实际在iOS5的时候已经被遗弃了,但是iOS7中已经完全的禁用了它.Xcode5甚至不会允许你编译包含了指引到-[UIDevice uniqueIdentifier]的app.此外,iOS7之前的使用了-[UIDevice uniqueIdentifier] 的app如果在iOS7上运行,它不会返回设备的

获取iOS设备的型号

获取iOS设备的型号 需要#import "sys/utsname.h"     structutsname systemInfo;     uname(&systemInfo);     NSString*deviceString = [NSStringstringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];          if([deviceString isEqualToString:@&

获取IOS设备的电量信息:Battery Level

本文介绍了如何通过API获取IOS设备的电量信息. 移动设备的电量消耗一直是一个大问题,APP开发中也不可避免地需要收集APP运行时的电量消耗信息,这也是APP性能的衡量标准之一. 首先需要打开iphone设置中的电量统计. 1.通过Instruments获取 Instruments工具自带的Energy Diagnostics工具可以获取到iphone特定时段的电量消耗信息.具体步骤: 打开Developer选项中的Start Logging -> 断开iphone与PC连接 -> 一系列的

【转】:获取IOS设备的型号

[转]:http://www.oschina.net/code/snippet_2247606_39106 获取IOS设备的型号 //获得设备型号 + (NSString *)getCurrentDeviceModel:(UIViewController *)controller { int mib[2]; size_t len; char *machine; mib[0] = CTL_HW; mib[1] = HW_MACHINE; sysctl(mib, 2, NULL, &len, NUL

ios 设备基本信息检测

开发ios确实会让人身心愉悦(相对于deskop,android),ios app更多的让人集中注意力到它本身的体验,性能.这非常好,我非常喜欢相对完美的事物. 最近遇到一些乱七八糟的需求.需要获取一些设备信息,网络情况.iOS 上开发非常简单有趣,除了一些乱七八糟的信息,例如:摄像头硬件信息,本地相册初始化时间(第一次拍照保存),等. 剩下一些信息就是我要的了: 还是代码演示: #define IOS_CELLULAR @"pdp_ip0" #define IOS_WIFI @&qu

获取iOS设备键盘高度

最近做了一个自定义键盘,首先是要知道iOS设备各种键盘的高度,下面就来说一下怎么获取键盘的高度. 主要是利用键盘弹出时的通知. 1.首先先随便建一个工程. 2.在工程的 -(void)viewDidload;函数中添加键盘弹出和隐藏的通知,具体代码如下: 1 //增加监听,当键盘出现或改变时收出消息 2 [[NSNotificationCenter defaultCenter] addObserver:self 3 selector:@selector(keyboardWillShow:) 4

【转】iOS设备的UDID是什么?苹果为什么拒绝获取iOS设备UDID的应用?如何替代UDID?

本文讲诉的主要是为什么苹果2011年8月发布iOS 5后就开始拒绝App获取设备的UDID以及UDID替补方案,特别提醒开发者苹果App Store禁止访问UDID的应用上架(相关推荐:APP被苹果App Store拒绝的N个原因),下面先来了解下UDID. 一.UDID是什么? UDID的全称是Unique Device Identifier,顾名思义,它就是苹果IOS设备的唯一识别码,它由40个字符的字母和数字组成. 二.UDID有什么用? 移动网络可利用UDID来识别移动设备,如iPhon