Explorar el Código

Leftovers from token->apns key changes

Jonas Björkert hace 1 año
padre
commit
781e1cc41b

+ 4 - 4
LoopFollow/Remote/PushNotificationManager.swift

@@ -19,7 +19,7 @@ class PushNotificationManager {
     private var deviceToken: String
     private var sharedSecret: String
     private var productionEnvironment: Bool
-    private var token: String
+    private var apnsKey: String
     private var teamId: String
     private var keyId: String
     private var user: String
@@ -32,7 +32,7 @@ class PushNotificationManager {
         self.deviceToken = Storage.shared.deviceToken.value
         self.sharedSecret = Storage.shared.sharedSecret.value
         self.productionEnvironment = Storage.shared.productionEnvironment.value
-        self.token = Storage.shared.token.value
+        self.apnsKey = Storage.shared.apnsKey.value
         self.teamId = Storage.shared.teamId.value
         self.keyId = Storage.shared.keyId.value
         self.user = Storage.shared.user.value
@@ -105,7 +105,7 @@ class PushNotificationManager {
         var missingFields = [String]()
         if deviceToken.isEmpty { missingFields.append("deviceToken") }
         if sharedSecret.isEmpty { missingFields.append("sharedSecret") }
-        if token.isEmpty { missingFields.append("token") }
+        if apnsKey.isEmpty { missingFields.append("token") }
         if teamId.isEmpty { missingFields.append("teamId") }
         if keyId.isEmpty { missingFields.append("keyId") }
         if user.isEmpty { missingFields.append("user") }
@@ -231,7 +231,7 @@ class PushNotificationManager {
         var jwt = JWT(header: header, claims: claims)
 
         do {
-            let privateKey = Data(token.utf8)
+            let privateKey = Data(apnsKey.utf8)
             let jwtSigner = JWTSigner.es256(privateKey: privateKey)
             let signedJWT = try jwt.sign(using: jwtSigner)
 

+ 9 - 9
LoopFollow/Remote/Settings/RemoteSettingsView.swift

@@ -87,6 +87,15 @@ struct RemoteSettingsView: View {
                             .padding(.vertical, 5)
                             .disabled(true)
 
+                        HStack {
+                            Text("APNS Key ID")
+                            TextField("Enter APNS Key ID", text: $viewModel.keyId)
+                                .autocapitalization(.none)
+                                .disableAutocorrection(true)
+                                .focused($focusedField, equals: .keyId)
+                                .multilineTextAlignment(.trailing)
+                        }
+
                         VStack(alignment: .leading) {
                             Text("APNS Key")
                             TextEditor(text: $viewModel.apnsKey)
@@ -110,15 +119,6 @@ struct RemoteSettingsView: View {
                         }
 
                         HStack {
-                            Text("Key ID")
-                            TextField("Enter Key ID", text: $viewModel.keyId)
-                                .autocapitalization(.none)
-                                .disableAutocorrection(true)
-                                .focused($focusedField, equals: .keyId)
-                                .multilineTextAlignment(.trailing)
-                        }
-
-                        HStack {
                             Text("Bundle ID")
                             TextField("Enter Bundle ID", text: $viewModel.bundleId)
                                 .autocapitalization(.none)

+ 1 - 6
LoopFollow/Storage/Storage.swift

@@ -14,7 +14,6 @@ class Storage {
     var deviceToken = StorageValue<String>(key: "deviceToken", default: "")
     var sharedSecret = StorageValue<String>(key: "sharedSecret", default: "")
     var productionEnvironment = StorageValue<Bool>(key: "productionEnvironment", default: true)
-    var token = StorageValue<String>(key: "token", default: "")
     var apnsKey = StorageValue<String>(key: "apnsKey", default: "")
     var teamId = StorageValue<String>(key: "teamId", default: "")
     var keyId = StorageValue<String>(key: "keyId", default: "")
@@ -28,9 +27,5 @@ class Storage {
 
     static let shared = Storage()
 
-    private init() {
-        if apnsKey.value.isEmpty && !token.value.isEmpty {
-            apnsKey = token // Migrate the old `token` value to `apnsKey` TODO: Remove this code later on.
-        }
-    }
+    private init() { }
 }