【发布时间】:2020-02-10 13:20:35
【问题描述】:
我有一个 react 原生应用。我正在尝试将 react native 与 ios 联系起来:
RCT_EXPORT_METHOD(getUserProfile:(RCTResponseSenderBlock)callback) {
Cosmote *cosmote = [[Cosmote alloc] init];
NSString * x;
NSString * str;
x = [cosmote getUserProfileWithCompletionHandler:^(NSString* string){string}]
callback(@[x]);
}
在 Cosmote.swift 中我有这个功能:
@objc
open func getUserProfile(completionHandler: @escaping (_ s: String) -> ()) {
let x = UserDetailsManager.self;
x.getUserDetails(completionBlock: {data in
print("got user Details")
var json:String = "{\"data\": {\"guid\": \"\(data.guid)\", \"email\": \"\(data.email)\", \"username\": \"\(data.username)\", \"firstName\": \"\(data.firstname)\", \"lastName\": \"\(data.lastname)\", \"otePortalStatus\": \"\(data.otePortalStatus)\", \"otePortalisCorporate\": \"\(data.otePortalisCorporate)\", \"otePortalUserLevel\": \"\(data.otePortalUserLevel)\", \"otePortalAuthenticationLevel\": \"\(data.otePortalAuthenticationLevel)\", \"otePortalPIN\": \"\(data.otePortalPIN)\", \"otePortalEbppActivationDate\": \"\(data.otePortalEbppActivationDate)\", \"otePortalEbppEcareNumber\": \"\(data.otePortalEbppEcareNumber)\", \"otePortalEbppStatus\": \"\(data.otePortalEbppStatus)\", \"otegroupPasswordDate\": \"\(data.otegroupPasswordDate)\", \"otegroupStatus\": \"\(data.otegroupStatus)\", \"otegroupPasswordExpiration\": \"\(data.otegroupPasswordExpiration)\", \"otegroupPasswordReset\": \"\(data.otegroupPasswordReset)\", \"otegroupRegistrationDate\": \"\(data.otegroupRegistrationDate)\", \"otegroupAlternativeEmail\": \"\(data.otegroupAlternativeEmail)\", \"otegroupAlternativeMSISDN\": \"\(data.otegroupAlternativeMSISDN)\", \"imageURL\": \"\(data.imageURL)\"}}"
completionHandler(json);
}, onError: {_ in
print("did not get user Details")
completionHandler("{}");
})
}
第一个函数:
x = [cosmote getUserProfileWithCompletionHandler:^(NSString* string){string}]
我收到了错误:
从不兼容的类型'void'分配给'NSString *__strong'
不兼容的块指针类型发送 'void (^)(NSString *__strong)' 转换为 'NSString * _Nonnull (^ _Nonnull)(NSString * _Nonnull __strong)' 类型的参数
我该如何解决这个问题?
【问题讨论】:
标签: objective-c swift react-native