-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can you support objective-c #37
Comments
Will need to figure this out. Looks like a similar issue to #13 |
you can add an adapter to support objective-c, like this. //
// SignalRClient.h
// Followme
//
// Created by Subo on 2018/12/25.
// Copyright © 2018年 com.followme. All rights reserved.
//
import Foundation
import SwiftSignalRClient
@objc public protocol SignalRClientDelegate : class {
func clientDidConnectSuccess(client: SignalRClient)
func clientDidConnectFailed(client: SignalRClient, error: Error)
func clientDidClosed(client: SignalRClient, error: Error?)
}
/// 因为SwiftSignalRClient没有做OC的支持,所以这里多包装了一层来支持OC
@objcMembers public class SignalRClient : NSObject {
var url: String
var headers: [String: String]?
private var connection: HubConnection?
public weak var delegate: SignalRClientDelegate?
public init(url: String, headers: [String: String]?) {
self.url = url
self.headers = headers
super.init()
}
public func start() {
self.connection = HubConnectionBuilder(url: URL(string: self.url)!)
.withLogging(minLogLevel: .debug)
.withHttpConnectionOptions(configureHttpOptions: { (httpConnectionOptions) in
if let header = self.headers {
for (key, value) in header {
httpConnectionOptions.headers[key] = value
}
}
})
.build()
self.connection?.delegate = self
self.connection?.start()
}
public func stop() {
self.connection?.stop()
}
public func on(method: String, callback: @escaping (_ jsonString: String?) -> Void) {
self.connection?.on(method: method, callback: {args, typeConverter in
if let json = args.first as? String {
callback(json)
return
}
callback(nil)
})
}
public func send(method: String, arguments:[AnyObject], sendDidComplete: @escaping (_ error: Error?) -> Void) {
self.connection?.send(method: method, arguments: arguments, sendDidComplete: sendDidComplete)
}
public func invoke(method: String, arguments: [AnyObject], invocationDidComplete: @escaping (_ error: Error?) -> Void) {
self.connection?.invoke(method: method, arguments: arguments, invocationDidComplete: invocationDidComplete)
}
}
extension SignalRClient: HubConnectionDelegate {
public func connectionDidOpen(hubConnection: HubConnection!) {
self.delegate?.clientDidConnectSuccess(client: self)
}
public func connectionDidFailToOpen(error: Error) {
self.delegate?.clientDidConnectFailed(client: self, error: error)
}
public func connectionDidClose(error: Error?) {
self.delegate?.clientDidClosed(client: self, error: error)
}
} You can use it like this. #import "YourTarget-Swift.h"
NSString *url = @"https://xxxxxxxxxxx";
NSDictionary *headers = @{@"token" : @"xxxxxxx"};
self.client = [[SignalRClient alloc] initWithUrl:url headers:headers];
self.client.delegate = self;
__weak __typeof(self)weakSelf = self;
[self.client onMethod:@"YourMethod" callback:^(NSString * _Nullable jsonString) {
NSLog(@"arguments: %@", jsonString);
}];
[self.client start];
|
@lexiaoyao20 - this is cool! |
@lexiaoyao20 - do you mind if I use your code as part of this project? |
NO problem. |
Thanks!
…On Wed, May 29, 2019 at 7:07 AM lexiaoyao20 ***@***.***> wrote:
@lexiaoyao20 <https://github.com/lexiaoyao20> - do you mind if I use your
code as part of this project?
NO problem.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#37?email_source=notifications&email_token=AAK7JJDWHIXOOHYKXQJQ4YDPX2E2NA5CNFSM4GHXUP22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWPOGTA#issuecomment-496952140>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAK7JJCHWHPWF3UUU5USZGDPX2E2NANCNFSM4GHXUP2Q>
.
|
I am trying to use SignalR-Client-Swift library on an objective C project when calling "start()". I'm getting next error.
@lexiaoyao20 or @moozzyk did you find a similar issue? Any tip would be appreciated! |
Seems like a data race in the WebSocket library. The stack trace points to this code: SignalR-Client-Swift/Sources/SignalRClient/WebSocket.swift Lines 1651 to 1656 in 9e235dc
but I don't immediately see anything there. I think the problem is that I don't know what code the other thread is running: |
I tried with a new obj-c project with just this pod, so no "external" code is involved, and either worked. From some checking what it comes to my mind is that some of the calls/structures (for example, mutex) are not fully supported by obj-c and that it is what is causing the "Swift access race". |
If anyone interested, there is a pull request for the WebSocket.swift file on its original repo, that solves this issue. Pull request: tidwall/SwiftWebSocket#141 |
@jaragones - this is a great find. My experience is that the SwiftWebSocket project is not actively maintained and PRs linger for a long time before they are merged (if ever). Fortunately, I forked the code so can take the fix without waiting for it to be merged in the SwiftWebSocket repo. |
Cool! Thanks for the library by the way! :) |
SwiftWebSocket has a threading issue described in #37 (comment). There is a PR in the SwiftWebSocket (tidwall/SwiftWebSocket#141) repo to fix the problem but it does not seem like it is going to be merged anytime soon so applying the fix locally. A nice post describing the problem: http://www.russbishop.net/the-law
I applied the fix from the PR so if you try master you should no longer see the TSAN issue. |
@jaragones - the version on CocoaPods now has the TSAN fix. |
Cool, I was importing the library manually on my project! Thanks to let me know. |
Is there any remaining work to support Objective-C? I am asking as the issue is still open, but from the conversation above it seems that @lexiaoyao20 @moozzyk and @jaragones have a working solution. |
I have not tried but I am not sure how well Objective-C works with |
You need to extend it on bridge with codable if response is not simple. But
apart from that on my case works like a charm. 😊
On Sat, 12 Oct 2019 at 23:00, Pawel Kadluczka ***@***.***> wrote:
I have not tried but I am not sure how well Objective-C works with Codable.
The real interop should allow the same flexibility as the Swift version and
a sane way of installing it into the project. What @lexiaoyao20
<https://github.com/lexiaoyao20> provided is great because it unblocks
the scenario but require at least some work to turn it into a reusable
framework solution. I started looking into it some time ago but given that
I do this in my free time I barely made any progress.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#37?email_source=notifications&email_token=AAQVYS5PIWG5HIE4XXQ27ETQOI3IBA5CNFSM4GHXUP22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBCIHSA#issuecomment-541361096>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQVYSY6NASVO7CBNHKOQCTQOI3IBANCNFSM4GHXUP2Q>
.
--
Sent from Gmail Mobile
|
I am not sure if this is simple to do in a generic way but good to hear
that it’s at least possible.
On Sun, Oct 13, 2019 at 11:50 AM Jordi Aragones-Vilella <
[email protected]> wrote:
… You need to extend it on bridge with codable if response is not simple. But
apart from that on my case works like a charm. 😊
On Sat, 12 Oct 2019 at 23:00, Pawel Kadluczka ***@***.***>
wrote:
> I have not tried but I am not sure how well Objective-C works with
Codable.
> The real interop should allow the same flexibility as the Swift version
and
> a sane way of installing it into the project. What @lexiaoyao20
> <https://github.com/lexiaoyao20> provided is great because it unblocks
> the scenario but require at least some work to turn it into a reusable
> framework solution. I started looking into it some time ago but given
that
> I do this in my free time I barely made any progress.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <
#37?email_source=notifications&email_token=AAQVYS5PIWG5HIE4XXQ27ETQOI3IBA5CNFSM4GHXUP22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBCIHSA#issuecomment-541361096
>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/AAQVYSY6NASVO7CBNHKOQCTQOI3IBANCNFSM4GHXUP2Q
>
> .
>
--
Sent from Gmail Mobile
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#37?email_source=notifications&email_token=AAK7JJC5FGYTV753TXUGIJ3QONUWPA5CNFSM4GHXUP22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBC5B7Q#issuecomment-541446398>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAK7JJFS5BTG6GDH5ROOCK3QONUWPANCNFSM4GHXUP2Q>
.
|
Has anyone tried https://github.com/DyKnow/SignalR-ObjC |
I believe the client you pointed to is for the old (i.e. non-Asp.Net Core)
version of SignalR.
…On Mon, Oct 14, 2019 at 9:11 AM Navneet Gupta ***@***.***> wrote:
Has anyone tried https://github.com/DyKnow/SignalR-ObjC
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#37?email_source=notifications&email_token=AAK7JJGSKIFKFYAJS7YBS4DQOSK3DA5CNFSM4GHXUP22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBFMNII#issuecomment-541771425>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAK7JJBLHKUZZWSEVMRA52LQOSK3DANCNFSM4GHXUP2Q>
.
|
public func send(method: String, arguments:[AnyObject], sendDidComplete: @escaping (_ error: Error?) -> Void) {
我按照你写的额,在oc里调用,但是不知道这个Encodable不知道对应OC里的什么修饰符号,最后报错 |
@aysw7331447
|
Demo for adding an adapter to support objective-c via SwiftSignalRClient |
@moozzyk any update on this? |
Can you support objective-c
The text was updated successfully, but these errors were encountered: