-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIDeviceAdditions.m
More file actions
111 lines (98 loc) · 2.79 KB
/
UIDeviceAdditions.m
File metadata and controls
111 lines (98 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// UIDeviceAdditions.m
// RedScarf
//
// Created by lishipeng on 15/12/9.
// Copyright © 2015年 zhangb. All rights reserved.
//
#import "UIDeviceAdditions.h"
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_dl.h>
#import <ifaddrs.h>
#import <sys/utsname.h>
#import "FCUUID.h"
@implementation UIDevice(HardWare)
+(NSString *) utm_campaign
{
return @"user";
}
+(NSString *) utm_source
{
return UTM_SOURCE;
}
+(NSString *) utm_content
{
return [FCUUID uuidForDevice];
}
+ (NSString *)networkStatus
{
NSString *connType = @"None";
struct ifaddrs * addrs;
const struct ifaddrs * cursor;
if (!getifaddrs(&addrs)) {
cursor = addrs;
while (cursor != NULL) {
// the second test keeps from picking up the loopback address
if (cursor->ifa_addr->sa_family == AF_INET && (cursor->ifa_flags & IFF_LOOPBACK) == 0) {
NSString *name = [NSString stringWithUTF8String:cursor->ifa_name];
NSLog(@"%@",name);
if ([name isEqualToString:@"en0"]) { // Wi-Fi adapter
connType = @"WiFi";
} else if ([name isEqualToString:@"lo0"] || [name isEqualToString:@"vmnet1"]) {
connType = @"None";
} else {
connType = @"GPRS";
}
//break;
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
return connType;
}
+ (BOOL)isPad
{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
}
+ (CGFloat)scale {
if ([UIScreen instancesRespondToSelector:@selector(scale)] && [UIScreen mainScreen].scale>1.0) {
return [UIScreen mainScreen].scale;
}
return 1.0f;
}
+ (BOOL)isRetina
{
if ([UIScreen instancesRespondToSelector:@selector(scale)] && [UIScreen mainScreen].scale>1.0) {
return YES;
}
return NO;
}
+ (BOOL)isSingleTask
{
struct utsname name;
uname(&name);
float version = [[UIDevice currentDevice].systemVersion floatValue];//判定系统版本。
if (version < 4.0 || strstr(name.machine, "iPod1,1") != 0 || strstr(name.machine, "iPod2,1") != 0) {
return YES;
} else {
return NO;
}
}
+ (NSString *)modelName
{
NSMutableArray *arr = [NSMutableArray array];
//第一参数为系统号
[arr addObject:@"ios"];
//第二参数为系统版本
[arr addObject:[[UIDevice currentDevice] systemVersion]];
//第三参数为机型
[arr addObject:[[[UIDevice currentDevice] model]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
return [arr componentsJoinedByString:@"|"];
}
+ (NSString *)clientVersion {
return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
}
@end