手机版
网站地图
美文美图
最新动态
你好,欢迎访问
好美文阅读网
个性皮肤
搜索
网站首页
美文
文章
散文
日记
诗歌
小说
故事
句子
作文
签名
祝福语
情书
范文
读后感
文学百科
美文摘抄
节日文章
名家散文
网名大全
座右铭
口号大全
面试技巧
说说大全
阅读答案
诗词默写
流言蜚语
节日祝福
好句子
经典台词
谚语大全
亲情故事
友情故事
表白情书
工作报告
活动总结
心得体会
专题汇总
美文网首页
iOS开发
获取苹果手机的信息(手机型号、IP地址)
获取苹果手机的信息(手机型号、IP地址)
作者:
风规自远
| 来源:发表于
2018-04-11 10:20 被阅读12次
//
// iPhoneInfoTool.h
// M
//
// Created by zsl on 2017/11/1.
// Copyright © 2017年 zsl. All rights reserved.
//
#import
@interfaceiPhoneInfoTool :NSObject
/**
根据操作系统获取苹果设备名称
@return 苹果设备名称名称
*/
+ (NSString *)getThePhoneNameAccordingToTheOperatingSystem;
/**
* 获取设备的IP地址
*/
+ (NSString *)getDeviceIpAddress;
@end
//
// iPhoneInfoTool.m
// M
//
// Created by zsl on 2017/11/1.
// Copyright © 2017年 zsl. All rights reserved.
//
#import "iPhoneInfoTool.h"
/**1、获取设备名称导入头文件*/
#import "sys/utsname.h"
/**2、获取IP地址导入头文件*/
#include
#include // Per msqr
#import
#include
#import
@implementation iPhoneInfoTool
/**
* 设备名称
*/
+ (NSString*)getThePhoneNameAccordingToTheOperatingSystem {
//需要#import "sys/utsname.h"
structutsnamesystemInfo;
uname(&systemInfo);
NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
//iPhone1,1为型号标识符
if([deviceStringisEqualToString:@"iPhone1,1"]) return@"iPhone 1G";
if([deviceStringisEqualToString:@"iPhone1,2"]) return@"iPhone 3G";
if([deviceStringisEqualToString:@"iPhone2,1"]) return@"iPhone 3GS";
if([deviceStringisEqualToString:@"iPhone3,1"]) return@"iPhone 4";
if ([deviceString isEqualToString:@"iPhone3,2"]) return @"Verizon iPhone 4";
if([deviceStringisEqualToString:@"iPhone4,1"]) return@"iPhone 4S";
if([deviceStringisEqualToString:@"iPhone5,1"]) return@"iPhone 5";
if([deviceStringisEqualToString:@"iPhone5,2"]) return@"iPhone 5";
if([deviceStringisEqualToString:@"iPhone5,3"]) return@"iPhone 5C";
if([deviceStringisEqualToString:@"iPhone5,4"]) return@"iPhone 5C";
if([deviceStringisEqualToString:@"iPhone6,1"]) return@"iPhone 5S";
if([deviceStringisEqualToString:@"iPhone6,2"]) return@"iPhone 5S";
if([deviceStringisEqualToString:@"iPhone7,1"]) return@"iPhone 6 Plus";
if([deviceStringisEqualToString:@"iPhone7,2"]) return@"iPhone 6";
if([deviceStringisEqualToString:@"iPhone8,1"]) return@"iPhone 6s";
if ([deviceString isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus";
if([deviceStringisEqualToString:@"iPhone8,4"]) return@"iPhone SE";
if([deviceStringisEqualToString:@"iPhone9,1"]) return@"iPhone 7";
if([deviceStringisEqualToString:@"iPhone9,3"]) return@"iPhone 7";
if([deviceStringisEqualToString:@"iPhone9,2"]) return@"iPhone 7 Plus";
if([deviceStringisEqualToString:@"iPhone9,4"]) return@"iPhone 7 Plus";
if([deviceStringisEqualToString:@"iPhone10,1"]) return@"iPhone 8";
if([deviceStringisEqualToString:@"iPhone10,4"]) return@"iPhone 8";
if ([deviceString isEqualToString:@"iPhone10,2"]) return @"iPhone 8 Plus";
if ([deviceString isEqualToString:@"iPhone10,5"]) return @"iPhone 8 Plus";
if([deviceStringisEqualToString:@"iPhone10,3"]) return@"iPhone X";
if([deviceStringisEqualToString:@"iPhone10,6"]) return@"iPhone X";
// iPod touch
if([deviceStringisEqualToString:@"iPod1,1"]) return@"iPod Touch 1G";
if([deviceStringisEqualToString:@"iPod2,1"]) return@"iPod Touch 2G";
if([deviceStringisEqualToString:@"iPod3,1"]) return@"iPod Touch 3G";
if([deviceStringisEqualToString:@"iPod4,1"]) return@"iPod Touch 4G";
if ([deviceString isEqualToString:@"iPod5,1"]) return @"iPod Touch (5 Gen)";
// iPad 平板电脑
if([deviceStringisEqualToString:@"iPad1,1"]) return@"iPad";
if([deviceStringisEqualToString:@"iPad1,2"]) return@"iPad 3G";
if([deviceStringisEqualToString:@"iPad2,1"]) return@"iPad 2 (WiFi)";
if([deviceStringisEqualToString:@"iPad2,2"]) return@"iPad 2";
if([deviceStringisEqualToString:@"iPad2,3"]) return@"iPad 2 (CDMA)";
if([deviceStringisEqualToString:@"iPad2,4"]) return@"iPad 2";
if([deviceStringisEqualToString:@"iPad2,5"]) return@"iPad Mini (WiFi)";
if([deviceStringisEqualToString:@"iPad2,6"]) return@"iPad Mini";
if ([deviceString isEqualToString:@"iPad2,7"]) return @"iPad Mini (GSM+CDMA)";
if([deviceStringisEqualToString:@"iPad3,1"]) return@"iPad 3 (WiFi)";
if([deviceStringisEqualToString:@"iPad3,2"]) return@"iPad 3 (GSM+CDMA)";
if([deviceStringisEqualToString:@"iPad3,3"]) return@"iPad 3";
if([deviceStringisEqualToString:@"iPad3,4"]) return@"iPad 4 (WiFi)";
if([deviceStringisEqualToString:@"iPad3,5"]) return@"iPad 4";
if([deviceStringisEqualToString:@"iPad3,6"]) return@"iPad 4 (GSM+CDMA)";
if([deviceStringisEqualToString:@"iPad4,1"]) return@"iPad Air (WiFi)";
if ([deviceString isEqualToString:@"iPad4,2"]) return @"iPad Air (Cellular)";
if ([deviceString isEqualToString:@"iPad4,4"]) return @"iPad Mini 2 (WiFi)";
if ([deviceString isEqualToString:@"iPad4,5"]) return @"iPad Mini 2 (Cellular)";
if([deviceStringisEqualToString:@"iPad4,6"]) return@"iPad Mini 2";
if([deviceStringisEqualToString:@"iPad4,7"]) return@"iPad Mini 3";
if([deviceStringisEqualToString:@"iPad4,8"]) return@"iPad Mini 3";
if([deviceStringisEqualToString:@"iPad4,9"]) return@"iPad Mini 3";
if ([deviceString isEqualToString:@"iPad5,1"]) return @"iPad Mini 4 (WiFi)";
if([deviceStringisEqualToString:@"iPad5,2"]) return@"iPad Mini 4 (LTE)";
if([deviceStringisEqualToString:@"iPad5,3"]) return@"iPad Air 2";
if([deviceStringisEqualToString:@"iPad5,4"]) return@"iPad Air 2";
if([deviceStringisEqualToString:@"iPad6,3"]) return@"iPad Pro 9.7";
if([deviceStringisEqualToString:@"iPad6,4"]) return@"iPad Pro 9.7";
if([deviceStringisEqualToString:@"iPad6,7"]) return@"iPad Pro 12.9";
if([deviceStringisEqualToString:@"iPad6,8"]) return@"iPad Pro 12.9";
if([deviceStringisEqualToString:@"AppleTV2,1"]) return@"Apple TV 2";
if([deviceStringisEqualToString:@"AppleTV3,1"]) return@"Apple TV 3";
if([deviceStringisEqualToString:@"AppleTV3,2"]) return@"Apple TV 3";
if([deviceStringisEqualToString:@"AppleTV5,3"]) return@"Apple TV 4";
if([deviceStringisEqualToString:@"i386"]) return@"Simulator";
if([deviceStringisEqualToString:@"x86_64"]) return@"Simulator";
returndeviceString;
}
/**
* 设备IP地址
*/
+ (NSString*)getDeviceIpAddress {
intsockfd =socket(AF_INET,SOCK_DGRAM,0);
NSMutableArray *ips = [NSMutableArray array];
intBUFFERSIZE =4096;
structifconfifc;
charbuffer[BUFFERSIZE], *ptr, lastname[IFNAMSIZ], *cptr;
structifreq*ifr, ifrcopy;
ifc.ifc_len= BUFFERSIZE;
ifc.ifc_buf= buffer;
if(ioctl(sockfd,SIOCGIFCONF, &ifc) >=0){
for(ptr = buffer; ptr < buffer + ifc.ifc_len; ){
ifr = (structifreq*)ptr;
intlen =sizeof(structsockaddr);
if(ifr->ifr_addr.sa_len> len) {
len = ifr->ifr_addr.sa_len;
}
ptr +=sizeof(ifr->ifr_name) + len;
if(ifr->ifr_addr.sa_family!=AF_INET)continue;
if((cptr = (char*)strchr(ifr->ifr_name,':')) !=NULL) *cptr =0;
if(strncmp(lastname, ifr->ifr_name,IFNAMSIZ) ==0)continue;
memcpy(lastname, ifr->ifr_name,IFNAMSIZ);
ifrcopy = *ifr;
ioctl(sockfd,SIOCGIFFLAGS, &ifrcopy);
if((ifrcopy.ifr_flags&IFF_UP) ==0)continue;
NSString *ip = [NSString stringWithFormat:@"%s", inet_ntoa(((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr)];
[ipsaddObject:ip];
}
}
close(sockfd);
NSString*deviceIP =@"";
for(inti=0; i < ips.count; i++) {
if(ips.count>0) {
deviceIP = [NSString stringWithFormat:@"%@",ips.lastObject];
}
}
returndeviceIP;
}
@end
相关文章
网友评论
iOS开发
本文标题:
获取苹果手机的信息(手机型号、IP地址)
本文链接:
https://www.haomeiwen.com/subject/fakahftx.html
延伸阅读
那年盛夏诗歌
环境监察队工作总结范文
优秀教师学习心得范文
华胥引的读后感300字
《Its red》教学反思范文
农资购销的合同范本
竞选中队委优秀演讲稿
辞金蹈海的成语解释
《世纪宝鼎》公开课教案设计
因为爱你,所以牵挂
今生今世红尘醉——美到
一个90后的内心独白
致已逝去的高中年华
深度阅读
您也可以注册成为美文阅读网的作者,发表您的原创作品、分享您的心情!
情人节
母亲节
重阳节
清明节
端午节
植树节
元宵节
妇女节
愚人节
圣诞节
父亲节
教师节
儿童节
劳动节
青年节
建军节
万圣节
平安夜
光棍节
中秋节
国庆节
感恩节
腊八节
更多话题
栏目导航
iOS开发
摄影
故事
互联网
读书
旅行
热点阅读
年入千万的农民工
图片选择页英文 iOS开发
家装学习培训:为什么“内行”做不过“外行”?
需要安装的软件
20180411
找女朋友,你知道本科和专科有啥区别?
童言无忌|我要当哲思宝宝
梦想是朵两生花
棉布刺绣水溶花边
乌镇——来过便不曾离开
iOS开发
iOS开发易忽略的工作-业务逻辑之外那些事
iOS 项目的目录结构能看出你的开发经验
iOS 关于禁止单个页面的边缘返回
iOS之商城应用中物品属性选择+购物车功能+订单确认
14- CoreBluetooth(搜索(自定义选择列表)+连接
简仿映客直播App
SVProgressHUD方法
Code4App-iOS开发 - 开源项目
纯代码实现CollectionView的headerView悬停
iOS开发——解析崩溃日志
网友评论