Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

new device properties

  • Loading branch information...
commit b4debc428dbc9b21688385be3077e57d921773fb 1 parent 4881836
@neilrahilly neilrahilly authored
View
16 HelloMixpanel/HelloMixpanel.xcodeproj/project.pbxproj
@@ -28,6 +28,8 @@
286760BD1611982600B1BEC8 /* MPCSerializedJSONData.m in Sources */ = {isa = PBXBuildFile; fileRef = 286760B51611982600B1BEC8 /* MPCSerializedJSONData.m */; };
286760BE1611982600B1BEC8 /* NSData+MPBase64.m in Sources */ = {isa = PBXBuildFile; fileRef = 286760B81611982600B1BEC8 /* NSData+MPBase64.m */; };
286760BF1611982600B1BEC8 /* Mixpanel.m in Sources */ = {isa = PBXBuildFile; fileRef = 286760BA1611982600B1BEC8 /* Mixpanel.m */; };
+ 2892541D16548047003DAFFE /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2892541C16548047003DAFFE /* SystemConfiguration.framework */; };
+ 2892541F16548283003DAFFE /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2892541E16548283003DAFFE /* CoreTelephony.framework */; };
28C7E667161530BF00F78E49 /* Icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 28C7E666161530BF00F78E49 /* Icon@2x.png */; };
28C7E6691615311100F78E49 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 28C7E6681615311100F78E49 /* Icon.png */; };
28C7E66B1615317400F78E49 /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = 28C7E66A1615317400F78E49 /* Icon-72.png */; };
@@ -76,6 +78,8 @@
286760B81611982600B1BEC8 /* NSData+MPBase64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+MPBase64.m"; sourceTree = "<group>"; };
286760B91611982600B1BEC8 /* Mixpanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Mixpanel.h; sourceTree = "<group>"; };
286760BA1611982600B1BEC8 /* Mixpanel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Mixpanel.m; sourceTree = "<group>"; };
+ 2892541C16548047003DAFFE /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
+ 2892541E16548283003DAFFE /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; };
28C7E666161530BF00F78E49 /* Icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon@2x.png"; sourceTree = "<group>"; };
28C7E6681615311100F78E49 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = "<group>"; };
28C7E66A1615317400F78E49 /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-72.png"; sourceTree = "<group>"; };
@@ -86,6 +90,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 2892541F16548283003DAFFE /* CoreTelephony.framework in Frameworks */,
+ 2892541D16548047003DAFFE /* SystemConfiguration.framework in Frameworks */,
2808F9921610EFE3005772B7 /* UIKit.framework in Frameworks */,
2808F9941610EFE3005772B7 /* Foundation.framework in Frameworks */,
2808F9961610EFE3005772B7 /* CoreGraphics.framework in Frameworks */,
@@ -128,6 +134,8 @@
2808F9901610EFE3005772B7 /* Frameworks */ = {
isa = PBXGroup;
children = (
+ 2892541E16548283003DAFFE /* CoreTelephony.framework */,
+ 2892541C16548047003DAFFE /* SystemConfiguration.framework */,
2808F9911610EFE3005772B7 /* UIKit.framework */,
2808F9931610EFE3005772B7 /* Foundation.framework */,
2808F9951610EFE3005772B7 /* CoreGraphics.framework */,
@@ -447,8 +455,8 @@
GCC_WARN_UNUSED_PARAMETER = NO;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
- PROVISIONING_PROFILE = "386F055C-7E38-4B03-AC0F-22EE5CA5FE24";
- "PROVISIONING_PROFILE[sdk=iphoneos*]" = "386F055C-7E38-4B03-AC0F-22EE5CA5FE24";
+ PROVISIONING_PROFILE = "0F5AB3F8-3831-45DE-A1AA-5408EE0097E3";
+ "PROVISIONING_PROFILE[sdk=iphoneos*]" = "0F5AB3F8-3831-45DE-A1AA-5408EE0097E3";
RUN_CLANG_STATIC_ANALYZER = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
@@ -525,8 +533,8 @@
INFOPLIST_FILE = "HelloMixpanel/HelloMixpanel-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
PRODUCT_NAME = "$(TARGET_NAME)";
- PROVISIONING_PROFILE = "386F055C-7E38-4B03-AC0F-22EE5CA5FE24";
- "PROVISIONING_PROFILE[sdk=iphoneos*]" = "386F055C-7E38-4B03-AC0F-22EE5CA5FE24";
+ PROVISIONING_PROFILE = "0F5AB3F8-3831-45DE-A1AA-5408EE0097E3";
+ "PROVISIONING_PROFILE[sdk=iphoneos*]" = "0F5AB3F8-3831-45DE-A1AA-5408EE0097E3";
WRAPPER_EXTENSION = app;
};
name = Debug;
View
76 Mixpanel/Mixpanel.m
@@ -22,11 +22,16 @@
#include <sys/sysctl.h>
#import <CommonCrypto/CommonHMAC.h>
+#import <CoreTelephony/CTCarrier.h>
+#import <CoreTelephony/CTTelephonyNetworkInfo.h>
+#import <SystemConfiguration/SystemConfiguration.h>
#import "MPCJSONDataSerializer.h"
#import "Mixpanel.h"
#import "NSData+MPBase64.h"
+#define VERSION @"1.0.0"
+
#ifndef IFT_ETHER
#define IFT_ETHER 0x6 // ethernet CSMACD
#endif
@@ -86,15 +91,37 @@ @implementation Mixpanel
+ (NSDictionary *)deviceInfoProperties
{
NSMutableDictionary *properties = [NSMutableDictionary dictionary];
+
+ UIDevice *device = [UIDevice currentDevice];
+
[properties setValue:@"iphone" forKey:@"mp_lib"];
- [properties setValue:[Mixpanel legacyDeviceModel] forKey:@"mp_device_model"];
- [properties setValue:[Mixpanel deviceModel] forKey:@"$ios_device_model"];
- [properties setValue:[Mixpanel osVersion] forKey:@"$ios_version"];
- [properties setValue:[Mixpanel appVersion] forKey:@"$ios_app_version"];
+ [properties setValue:VERSION forKey:@"$lib_version"];
+
+ [properties setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] forKey:@"$app_version"];
+
+ [properties setValue:@"Apple" forKey:@"$manufacturer"];
+ [properties setValue:[device systemName] forKey:@"$os"];
+ [properties setValue:[device systemVersion] forKey:@"$os_version"];
+ [properties setValue:[Mixpanel deviceModel] forKey:@"$model"];
+ [properties setValue:[Mixpanel deviceModel] forKey:@"mp_device_model"]; // legacy
+
+ CGSize size = [UIScreen mainScreen].bounds.size;
+ [properties setValue:[NSNumber numberWithInt:(int)size.height] forKey:@"$screen_height"];
+ [properties setValue:[NSNumber numberWithInt:(int)size.width] forKey:@"$screen_width"];
+
+ [properties setValue:[NSNumber numberWithBool:[Mixpanel wifiAvailable]] forKey:@"$wifi"];
+
+ CTTelephonyNetworkInfo *networkInfo = [[[CTTelephonyNetworkInfo alloc] init] autorelease];
+ CTCarrier *carrier = [networkInfo subscriberCellularProvider];
+
+ if (carrier.carrierName.length) {
+ [properties setValue:carrier.carrierName forKey:@"$carrier"];
+ }
+
return [NSDictionary dictionaryWithDictionary:properties];
}
-+ (NSString *)legacyDeviceModel
++ (NSString *)deviceModel
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
@@ -108,19 +135,33 @@ + (NSString *)legacyDeviceModel
return results;
}
-+ (NSString *)deviceModel
++ (BOOL)wifiAvailable
{
- return [[UIDevice currentDevice] model];
-}
+ struct sockaddr_in sockAddr;
+ bzero(&sockAddr, sizeof(sockAddr));
+ sockAddr.sin_len = sizeof(sockAddr);
+ sockAddr.sin_family = AF_INET;
-+ (NSString *)osVersion
-{
- return [[UIDevice currentDevice] systemVersion];
-}
+ SCNetworkReachabilityRef nrRef = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&sockAddr);
+ SCNetworkReachabilityFlags flags;
+ BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(nrRef, &flags);
+ if (!didRetrieveFlags) {
+ DevLog(@"%@ unable to fetch the network reachablity flags", self);
+ }
-+ (NSString *)appVersion
-{
- return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
+ CFRelease(nrRef);
+
+ if (!didRetrieveFlags || (flags & kSCNetworkReachabilityFlagsReachable) != kSCNetworkReachabilityFlagsReachable) {
+ // unable to connect to a network (no signal or airplane mode activated)
+ return NO;
+ }
+
+ if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) {
+ // only a cellular network connection is available.
+ return NO;
+ }
+
+ return YES;
}
+ (BOOL)inBackground
@@ -928,10 +969,11 @@ @implementation MixpanelPeople
+ (NSDictionary *)deviceInfoProperties
{
+ UIDevice *device = [UIDevice currentDevice];
NSMutableDictionary *properties = [NSMutableDictionary dictionary];
[properties setValue:[Mixpanel deviceModel] forKey:@"$ios_device_model"];
- [properties setValue:[Mixpanel osVersion] forKey:@"$ios_version"];
- [properties setValue:[Mixpanel appVersion] forKey:@"$ios_app_version"];
+ [properties setValue:[device systemVersion] forKey:@"$ios_version"];
+ [properties setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] forKey:@"$ios_app_version"];
return [NSDictionary dictionaryWithDictionary:properties];
}
Please sign in to comment.
Something went wrong with that request. Please try again.