{"action":"created","issue":{"url":"https://api.github.com/repos/TimOliver/TOSMBClient/issues/55","repository_url":"https://api.github.com/repos/TimOliver/TOSMBClient","labels_url":"https://api.github.com/repos/TimOliver/TOSMBClient/issues/55/labels{/name}","comments_url":"https://api.github.com/repos/TimOliver/TOSMBClient/issues/55/comments","events_url":"https://api.github.com/repos/TimOliver/TOSMBClient/issues/55/events","html_url":"https://github.com/TimOliver/TOSMBClient/issues/55","id":277768326,"number":55,"title":"Asynchronous (request-)call not working properly","user":{"login":"rajderks","id":2419711,"avatar_url":"https://avatars3.githubusercontent.com/u/2419711?v=4","gravatar_id":"","url":"https://api.github.com/users/rajderks","html_url":"https://github.com/rajderks","followers_url":"https://api.github.com/users/rajderks/followers","following_url":"https://api.github.com/users/rajderks/following{/other_user}","gists_url":"https://api.github.com/users/rajderks/gists{/gist_id}","starred_url":"https://api.github.com/users/rajderks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rajderks/subscriptions","organizations_url":"https://api.github.com/users/rajderks/orgs","repos_url":"https://api.github.com/users/rajderks/repos","events_url":"https://api.github.com/users/rajderks/events{/privacy}","received_events_url":"https://api.github.com/users/rajderks/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-11-29T14:11:32Z","updated_at":"2017-12-05T08:34:35Z","closed_at":null,"author_association":"NONE","body":"## Hardware / Software\r\n\r\nWhich version of the library were you using? **1.0.8 (cocoa pods latest)**\r\nWhich version of iOS are you running? **11.0**\r\nWhat model of iOS device were you testing on? **iPhone SE, some iPad (not air or pro)**\r\nIf using CocoaPods, which version of CocoaPods are you on? **1.3.1**\r\n**USING SWIFT 4, xCode 9.1**\r\n\r\n## Goals\r\n\r\nWhat is the outcome result you want to achieve with this library?\r\nRequest files from local SMB server (MacBook High Sierra, public folder sharing using SMB, with account + password)\r\n\r\n## Expected Results\r\n\r\nWhat did you expect to happen?\r\nA listing of my public folder\r\n```\r\nSYNC CALL : Optional([Dir - Name: Drop Box | Size: 0, File - Name: 31F6603F-3251-4A51-8516-A67C8080A751.mp4 | Size: 1137622])\r\nASYNC CALL: Optional([Dir - Name: Drop Box | Size: 0, File - Name: 31F6603F-3251-4A51-8516-A67C8080A751.mp4 | Size: 1137622])\r\n```\r\n\r\n## Actual Results\r\n```\r\nSYNC CALL : Optional([Dir - Name: Drop Box | Size: 0, File - Name: 31F6603F-3251-4A51-8516-A67C8080A751.mp4 | Size: 1137622])\r\nASYNC CALL: nil\r\n```\r\n\r\n## Steps to Reproduce\r\n\r\nWhat are the steps needed to reproduce this issue?\r\n```\r\n        let session = TOSMBSession.init(hostName: \"xxx\", ipAddress: \"192.xxx.x.xxx\")\r\n        session?.setLoginCredentialsWithUserName(\"redacted\", password: \"super-redacted\")\r\n\r\n        let content = try! session?.requestContentsOfDirectory(atFilePath: \"/<public folder>/\")\r\n        print(\"\\(String(describing: content))\") // Prints the files\r\n        \r\n        session?.requestContentsOfDirectory(atFilePath: \"/<public folder>/\", success: { (content) in\r\n            print(\"\\(String(describing: content))\") // Always prints nil\r\n        }, error: { (error) in\r\n            if let error = error {\r\n                print(error.localizedDescription)\r\n            }\r\n        })\r\n```\r\n\r\nAfter tracing its steps, the asynchronous call never calls the synchronous call\r\n**TOSMBSession.m:353**        ` NSArray *files = [**weakSelf** requestContentsOfDirectoryAtFilePath:path error:&error];`\r\n\r\nChaning **weakSelf** to **self** fixes the issue, and works as expected. However, I do not know what consequences this might have.\r\n"},"comment":{"url":"https://api.github.com/repos/TimOliver/TOSMBClient/issues/comments/349232896","html_url":"https://github.com/TimOliver/TOSMBClient/issues/55#issuecomment-349232896","issue_url":"https://api.github.com/repos/TimOliver/TOSMBClient/issues/55","id":349232896,"user":{"login":"TimOliver","id":429119,"avatar_url":"https://avatars0.githubusercontent.com/u/429119?v=4","gravatar_id":"","url":"https://api.github.com/users/TimOliver","html_url":"https://github.com/TimOliver","followers_url":"https://api.github.com/users/TimOliver/followers","following_url":"https://api.github.com/users/TimOliver/following{/other_user}","gists_url":"https://api.github.com/users/TimOliver/gists{/gist_id}","starred_url":"https://api.github.com/users/TimOliver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimOliver/subscriptions","organizations_url":"https://api.github.com/users/TimOliver/orgs","repos_url":"https://api.github.com/users/TimOliver/repos","events_url":"https://api.github.com/users/TimOliver/events{/privacy}","received_events_url":"https://api.github.com/users/TimOliver/received_events","type":"User","site_admin":false},"created_at":"2017-12-05T08:34:35Z","updated_at":"2017-12-05T08:34:35Z","author_association":"OWNER","body":"Thanks for the issue @rajderks!\r\n\r\nI think the issue here is you need to hang onto your `session` object more permanently. I think what's happening here is you're creating it, performing this asynchronous request, and then by the time it completes, this original method has already completed and `session` has already been deallocated.\r\n\r\nIf you make `session` a property of your parent class, that should fix it.\r\n\r\nHope that helps!"}}
{"actor":{"display_login":"TimOliver"}}