Просмотр исходного кода

Add guidance message for production env setting

codebymini 10 месяцев назад
Родитель
Сommit
55b11b2a00

+ 28 - 13
LoopFollow/Remote/LoopAPNS/LoopAPNSService.swift

@@ -217,6 +217,30 @@ class LoopAPNSService {
 
     /// Provides environment-specific guidance for APNS configuration
     /// - Returns: String with guidance based on build configuration
+    private func getEnvironmentGuidance() -> String {
+        #if DEBUG
+            let buildType = "Xcode"
+            let recommendedEnvironment = "Development"
+            let environmentSetting = "Production Environment: OFF"
+        #else
+            let buildType = "Browser/TestFlight"
+            let recommendedEnvironment = "Production"
+            let environmentSetting = "Production Environment: ON"
+        #endif
+
+        let currentEnvironment = storage.productionEnvironment.value ? "Production" : "Development"
+
+        return """
+        Environment Configuration Help:
+
+        Build Type: \(buildType)
+        Current Setting: \(currentEnvironment)
+        Recommended Setting: \(recommendedEnvironment)
+
+        Please check your Loop Remote control settings:
+        • If you built with Xcode: Set "\(environmentSetting)"
+        • If you built with Browser/TestFlight: Set "Production Environment: ON"
+        """
     }
 
     /// Sends an APNS notification
@@ -321,19 +345,10 @@ class LoopAPNSService {
                         LogManager.shared.log(category: .apns, message: "APNS notification sent successfully")
                         completion(true, nil)
                     case 400:
-                    let errorResponse = String(data: data, encoding: .utf8) ?? "Unknown error"
-                    LogManager.shared.log(category: .apns, message: "APNS error 400: \(errorResponse)")
-                    LogManager.shared.log(category: .apns, message: "BadDeviceToken error - this usually means:")
-                    LogManager.shared.log(category: .apns, message: "1. Device token is expired or invalid")
-                    LogManager.shared.log(category: .apns, message: "2. Device token is from different environment (dev vs prod)")
-                    LogManager.shared.log(category: .apns, message: "3. Device token is not registered for this bundle identifier")
-                    LogManager.shared.log(category: .apns, message: "Troubleshooting steps:")
-                    LogManager.shared.log(category: .apns, message: "1. Refresh device token from Loop app")
-                    LogManager.shared.log(category: .apns, message: "2. Check if Loop app is using same environment (dev/prod)")
-                    LogManager.shared.log(category: .apns, message: "3. Verify device token is for bundle ID: \(bundleIdentifier)")
-                    LogManager.shared.log(category: .apns, message: "4. Check if device token is from production environment")
-                    LogManager.shared.log(category: .apns, message: "Current environment: \(storage.productionEnvironment.value ? "Production" : "Development")")
-                    throw LoopAPNSError.invalidResponse
+                        let environmentGuidance = self.getEnvironmentGuidance()
+                        let errorMessage = "Bad request. The request was invalid or malformed. \(responseBodyMessage)\n\n\(environmentGuidance)"
+                        LogManager.shared.log(category: .apns, message: "APNS error 400: \(responseBodyMessage) - Check device token and environment settings")
+                        completion(false, errorMessage)
                     case 403:
                         let errorMessage = "Authentication error. Check your certificate or authentication token. \(responseBodyMessage)"
                         LogManager.shared.log(category: .apns, message: "APNS error 403: \(responseBodyMessage) - Check APNS key permissions for bundle ID")

+ 30 - 1
LoopFollow/Remote/TRC/PushNotificationManager.swift

@@ -287,7 +287,8 @@ class PushNotificationManager {
                     case 200:
                         completion(true, nil)
                     case 400:
-                        completion(false, "Bad request. The request was invalid or malformed. \(responseBodyMessage)")
+                        let environmentGuidance = self.getEnvironmentGuidance()
+                        completion(false, "Bad request. The request was invalid or malformed. \(responseBodyMessage)\n\n\(environmentGuidance)")
                     case 403:
                         completion(false, "Authentication error. Check your certificate or authentication token. \(responseBodyMessage)")
                     case 404:
@@ -325,4 +326,32 @@ class PushNotificationManager {
         let urlString = "https://\(host)/3/device/\(deviceToken)"
         return URL(string: urlString)
     }
+
+    /// Provides environment-specific guidance for APNS configuration
+    /// - Returns: String with guidance based on build configuration
+    private func getEnvironmentGuidance() -> String {
+        #if DEBUG
+            let buildType = "Xcode"
+            let recommendedEnvironment = "Development"
+            let environmentSetting = "Production Environment: OFF"
+        #else
+            let buildType = "Browser/TestFlight"
+            let recommendedEnvironment = "Production"
+            let environmentSetting = "Production Environment: ON"
+        #endif
+
+        let currentEnvironment = productionEnvironment ? "Production" : "Development"
+
+        return """
+        Environment Configuration Help:
+
+        Build Type: \(buildType)
+        Current Setting: \(currentEnvironment)
+        Recommended Setting: \(recommendedEnvironment)
+
+        Please check your Trio Remote control settings:
+        • If you built with Xcode: Set "\(environmentSetting)"
+        • If you built with Browser/TestFlight: Set "Production Environment: ON"
+        """
+    }
 }