Skip to content

Commit 266f25c

Browse files
committed
[Optimize]Remove deprecated and unsafe usage
1. The onMessage interface of statelistener is deprecated. 2. Use a safer method to obtain the TemplateView.
1 parent 96dc8c7 commit 266f25c

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

debug_router/ios/DebugRouter.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ virtual void OnClose(int32_t code, const std::string &reason) override {
9696
[listener_ios_ onClose:code withReason:[NSString stringWithUTF8String:reason.c_str()]];
9797
}
9898
virtual void OnMessage(const std::string &message) override {
99-
[listener_ios_ onMessage:[NSString stringWithUTF8String:message.c_str()]];
99+
// do nothing
100100
}
101101
virtual void OnError(const std::string &error) override {
102102
[listener_ios_ onError:[NSString stringWithUTF8String:error.c_str()]];

debug_router/ios/DebugRouterInternalStateListener.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ - (void)onOpen:(ConnectionType)type {
2727
}];
2828
// TODO(zhoumingsong.smile) report
2929
}
30+
3031
- (void)onClose:(NSInteger)code withReason:(nonnull NSString *)reason {
3132
// TODO(zhoumingsong.smile) report
3233
// TODO(zhoumingsong.smile) Toast
3334
}
34-
- (void)onMessage:(nonnull NSString *)message {
35-
// do nothing
36-
}
35+
3736
- (void)onError:(nonnull NSString *)error {
3837
// TODO(zhoumingsong.smile) report
3938
// TODO(zhoumingsong.smile) Toast

debug_router/ios/DebugRouterSlot.mm

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,20 @@ - (NSString *)getTemplateUrl {
7272

7373
- (UIView *)getTemplateView {
7474
if (self.delegate) {
75-
SEL sel = NSSelectorFromString(@"getTemplateView");
76-
if ([self.delegate respondsToSelector:sel]) {
77-
id res = [self.delegate performSelector:sel];
78-
UIView *view = (UIView *)res;
79-
return view;
75+
SEL sel = @selector(getTemplateView);
76+
id delegate = (id)self.delegate;
77+
if ([delegate respondsToSelector:sel]) {
78+
NSMethodSignature *signature = [delegate methodSignatureForSelector:sel];
79+
if (signature) {
80+
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
81+
[invocation setTarget:delegate];
82+
[invocation setSelector:sel];
83+
[invocation invoke];
84+
85+
UIView *view = nil;
86+
[invocation getReturnValue:&view];
87+
return view;
88+
}
8089
}
8190
}
8291
return nil;

debug_router/ios/public/DebugRouter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ typedef enum : NSUInteger { ConnectionTypeWebSocket, ConnectionTypeUSB, Unknown
1616
@required
1717
- (void)onOpen:(ConnectionType)type;
1818
- (void)onClose:(NSInteger)code withReason:(nonnull NSString *)reason;
19-
- (void)onMessage:(nonnull NSString *)message __attribute__((deprecated("will remove")));
2019
- (void)onError:(nonnull NSString *)error;
2120

2221
@end

debug_router/ios/public/DebugRouterGlobalHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ NS_ASSUME_NONNULL_BEGIN
77
@protocol DebugRouterGlobalHandler <NSObject>
88

99
@required
10-
- (void)openCard:(NSString *)url __attribute__((deprecated("will remove")));
10+
- (void)openCard:(NSString *)url;
1111

1212
- (void)onMessage:(NSString *)message withType:(NSString *)type;
1313

0 commit comments

Comments
 (0)