Răsfoiți Sursa

Replace spaces in ClientPlatform; convert "iPhone OS" to iOS

Old iOS (~9.0) reports "iPhone OS" as the system name, instead of iOS. This has two problems: 1) Our servers reject spaces in the ClientPlatform; 2) having a different value makes it painful to do stats queries. So we'll map the old value to the new, and replace spaces to be safe.
Adam Pritchard 9 ani în urmă
părinte
comite
a1c0f88dc6

+ 18 - 5
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m

@@ -286,18 +286,31 @@
     // Fill in the rest of the values.
     //
     
-    // Ensure the elements of the ClientPlatform do not contain underscores, as that's what we use to separate the elements.
-    // Like "iOS"
-    NSString *systemName = [[[UIDevice currentDevice] systemName] stringByReplacingOccurrencesOfString:@"_" withString:@"-"];
+    // ClientPlatform must not contain:
+    //   - underscores, which are used by us to separate the constituent parts
+    //   - spaces, which are considered invalid by the server
+    // Like "iOS". Older iOS reports "iPhone OS", which we will convert.
+    NSString *systemName = [[UIDevice currentDevice] systemName];
+    if ([systemName isEqual: @"iPhone OS"]) {
+        systemName = @"iOS";
+    }
+    systemName = [[systemName
+                   stringByReplacingOccurrencesOfString:@"_" withString:@"-"]
+                  stringByReplacingOccurrencesOfString:@" " withString:@"-"];
     // Like "10.2.1"
-    NSString *systemVersion = [[[UIDevice currentDevice]systemVersion] stringByReplacingOccurrencesOfString:@"_" withString:@"-"];
+    NSString *systemVersion = [[[[UIDevice currentDevice]systemVersion]
+                                stringByReplacingOccurrencesOfString:@"_" withString:@"-"]
+                               stringByReplacingOccurrencesOfString:@" " withString:@"-"];
+    
     // "unjailbroken"/"jailbroken"
     NSString *jailbroken = @"unjailbroken";
     if ([JailbreakCheck isDeviceJailbroken]) {
         jailbroken = @"jailbroken";
     }
     // Like "com.psiphon3.browser"
-    NSString *bundleIdentifier = [[[NSBundle mainBundle] bundleIdentifier] stringByReplacingOccurrencesOfString:@"_" withString:@"-"];
+    NSString *bundleIdentifier = [[[[NSBundle mainBundle] bundleIdentifier]
+                                   stringByReplacingOccurrencesOfString:@"_" withString:@"-"]
+                                  stringByReplacingOccurrencesOfString:@" " withString:@"-"];
     
     NSString *clientPlatform = [NSString stringWithFormat:@"%@_%@_%@_%@",
                                 systemName,