QuickBlox / quickblox-ios-sdk

QuickBlox iOS SDK for messaging and video calling
https://quickblox.com/developers/IOS
MIT License
397 stars 358 forks source link

Cannot get chat dialogs even after login in Share Extension #1124

Closed kautham closed 4 years ago

kautham commented 5 years ago

I have a chat app with share extension. I want to send the messages even from the share extension. I have saved the current users quickblox id and the current user's friends quickblox ids in the shared app groups userdefaults from the main app and accessed them in the share extension.

But when i try to get the chat dialog object for sending the message i get the error in the shared extension

error: Request failed: client error (422) reasons: { errors = { base = ( "Forbidden. Need user." ); }; }

Environment details iOS Version | 12.0 and 12.1 |
Quickblox iOS SDK version | 2.15 | QuickbloxWebRTC SDK version | 2.6.3 |
Xcode Version | Xcode 10.1 |

what i am doing in my viewWillAppear() function is as below

            QuickBloxSettings()
            if QBChat.instance.manualInitialPresence == true {
                QBChat.instance.manualInitialPresence = false
            }

            if QBChat.instance.isConnected == false
            {
                if let qbId = getQuickbloxUserId() as? Int
                {
                    let user = QBUUser()
                    user.id = UInt(qbId)

                    var strPWDEncode : String?
                    strPWDEncode = QUICKBLOX_PASSWORD

                    user.password = strPWDEncode
                    QBChat.instance.connect(with: user, completion: { (error) in
                        QBChat.instance.addDelegate(self)
                        if error == nil   /// Login Always succeeded 
                        {

                            SKChatManager.sharedInstance().delegate = self
                            print("Session token") 
                            print(QBSession.current.sessionDetails?.token) // Prints Successfully

                            for i in 0..<resultObject.count // My Custom Chat room object from Userdefaults
                            {
                                let roomObj = resultObject.object(at: i) as? ChatRoom
                                //arrProfileIds.add((roomObj?.group_id)!)
                                print(roomObj?.group_id!)
                                print((roomObj?.qDialogId)) //QBDialog object id prints and is present

                                let reponsePage = QBResponsePage(limit: 1, skip: 0)
                                let extendedRequest : [String : String]  = ["_id" : (roomObj?.qDialogId)!]

                                QBRequest.dialogs(for: reponsePage, extendedRequest: extendedRequest, successBlock: { (response, chatDilog, sets, pageResponse) in

                                // This block never gets executed
                                }, errorBlock: { (response) in

                                    print("ERROR MESSAGE :", response) // This always called
                                })
                            }
                        }else {
                            print("Login Failed")
                        }
                    })
                }
            }

My log file is as below.

2019-01-23 04:40:54.206309+0530 ChatShare[2244:124142] [QBCore]: Request[1]:
POST URL:https://xxxxxx.quickblox.com/chat/Dialog.json
headers: {
    "Accept-Language" = "en-IN;q=1";
    "Content-Type" = "application/x-www-form-urlencoded";
    "QB-OS" = "iOS 12.1.2";
    "QB-SDK" = "iOS 2.15";
    "QB-Token" = 90d02a4a8f70908a4091fe1513c560df54000008;
    "QuickBlox-REST-API-Version" = "0.1.1";
    "User-Agent" = "SpakkChatShare/1.0 (iPhone; iOS 12.1.2; Scale/3.00)";
}
parameters: {
    "occupants_ids" = 63984;
    type = 3;
}
2019-01-23 04:40:55.018244+0530 SpakkChatShare[2244:124156] [QBCore]: Response[1]
headers: {
    "Access-Control-Allow-Origin" = "*";
    "Cache-Control" = "no-cache";
    Connection = "keep-alive";
    "Content-Type" = "application/json; charset=utf-8";
    Date = "Tue, 22 Jan 2019 23:10:54 GMT";
    Duration = "0.810803";
    "QB-Token-ExpirationDate" = "2019-01-23 01:10:54 UTC";
    "QuickBlox-REST-API-Version" = "0.1.1";
    Server = "nginx/1.12.1";
    "Set-Cookie" = "_mkra_ctxt=caca2d3794dd9a2904a6bc3f9782826f--422; path=/; max-age=5; HttpOnly; secure";
    Status = "422 Unprocessable Entity";
    "Strict-Transport-Security" = "max-age=31536000";
    "Transfer-Encoding" = Identity;
    "X-Content-Type-Options" = nosniff;
    "X-Frame-Options" = SAMEORIGIN;
    "X-Request-Id" = "4b933218-e678-4ef6-bc06-fcd4cdc1990f";
    "X-Runtime" = "0.011017";
    "X-XSS-Protection" = "1; mode=block";
}
error: Request failed: client error (422)
reasons: {
    errors =     {
        base =         (
            "Forbidden. Need user."
        );
    };
}

Keychain sharing between the 2 apps are enabled.

Am I missing something ?

ghost commented 5 years ago

Hello, dear @kautham

Thank you for contacting QuickBlox support. I already sent the reported issue to our developers. As soon as they provide me with any result, i will let you know.

ghost commented 4 years ago

The status of the ticket changed to "Closed" due to inactivity. If the reported issue is still actual for you - please reopen the ticket.