返回首页
当前位置: 主页 > 手机mobile >

探測設備類型iphone,ipad,ipodtouch

时间:2010-07-28 11:23来源:未知 作者:sam.huang 点击:
由於蘋果的產品線很豐富,我們生產的程序也需要適應多種類型的設備,所以有時候適用於iphone的電話功能,不能適用於ipod touch,所以有必要對這幾種設備進行區分對待.(這裡面沒有做過ip
  

由於蘋果的產品線很豐富,我們生產的程序也需要適應多種類型的設備,所以有時候適用於iphone的電話功能,不能適用於ipod touch,所以有必要對這幾種設備進行區分對待.(這裡面沒有做過ipad 3g的測試)

頭文件:

  1. #import <UIKit/UIKit.h> 
  2. @interface UIDevice(machine) 
  3. - (NSString *)machine; 
  4. @end 

具體文件:

  1. #import "UIDevice+machine.h" 
  2. #include <sys/types.h> 
  3. #include <sys/sysctl.h> 
  4.  
  5. @implementation UIDevice(machine) 
  6.  
  7. - (NSString *)machine 
  8.     size_t size; 
  9.     // Set 'oldp' parameter to NULL to get the size of the data 
  10.     // returned so we can allocate appropriate amount of space 
  11.     sysctlbyname("hw.machine", NULL, &size, NULL, 0);  
  12.     // Allocate the space to store name 
  13.     char *name = malloc(size); 
  14.     // Get the platform name 
  15.     sysctlbyname("hw.machine", name, &size, NULL, 0); 
  16.     // Place name into a string 
  17.     NSString *machine = [NSString stringWithCString:name encoding:[NSString defaultCStringEncoding]]; 
  18.     // Done with this 
  19.     free(name); 
  20.     return machine; 
  21. @end 

 

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
最新评论 查看所有评论
发表评论 查看所有评论
发布者资料
amw 查看详细资料 发送留言 加为好友 用户等级:高级会员 注册时间:2009-03-30 13:03 最后登录:2012-01-17 11:01
推荐内容