0

What we are doing

  1. We are hitting endpoint from Swift share extension and our main app is in Flutter. We are just trying to accomplish share suggestion feature from swift native.
  2. As you can see we have invoked Swift method from flutter and passed data like token and uuid as a arguments from flutter.
  3. We are using firebase token in our main app and for the refresh token we are signInSilently as a google user from the app.

Main Issue

  1. As we are getting token from our main flutter app but after 1 hour firebase token will expire and share extension will also not work as we cannot get another token from the share extension itself and cannot hit refresh token either.
  2. From the share extension feature we cannot even hit that signInSilently so we got into the trouble.
  3. Is there any way that we can access token again or refresh token and make share extension work smoothly after 1 hour as well.
func shareTextAndFileDataToPerr(){
        let sharedDefault = UserDefaults(suiteName: "group.com.perrs.app")!
        let token = sharedDefault.object(forKey: "token")
        let uuid1 = sharedDefault.object(forKey: "uuid1")
        let uuid2 = sharedDefault.object(forKey: "uuid2")
        let sharedBy = sharedDefault.object(forKey: "sharedBy")
        
        
        var documentList:Array<Dictionary<String,Any>> = []
        
        if(isText) {
            documentList.append(["attribute": "text", "key": "","document": textData,"size": 0])
        }
        else {
            for i in 0...fileSize.count-1 {
                documentList.append(["attribute": "\(fileExtension[i])","key": key[i],"document": fileNameWithExtension[i],"size":fileSize[i]])
            }
        }

        let data: [String: Any] = ["documents": documentList, "shared_by": sharedBy!, "shared_to": uuid1!]
        
        // Create a URLRequest with the URL of the server endpoint
        var request = URLRequest(url: URL(string: "https://perr.myjobladder.com/data/")!)
        request.httpMethod = "POST"
        request.allHTTPHeaderFields = [
            "Content-Type": "application/json",
            "Authorization":"Bearer \(token!)"
            
        ]
        request.httpBody = try? JSONSerialization.data(withJSONObject: data, options: .prettyPrinted)

        let task = URLSession.shared.dataTask(with: request) { data, response, error in
            
            guard data != nil else {
                            print("data is nil")
                            return
                        }

            // Handle the response from the server here
            let jsonResponse = try? JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? [String: Any]

            print(jsonResponse as Any);
            
//            Remove Loader at last
            self.stopLoader()
            
      
        }
        task.resume()
    }

Any kind of help in this project would be much appreciated and thankful.

0 Answers0