如何将数据从viewController发送到NSObject类层次结构,反之亦然

时间:2015-03-27 13:12:51

标签: ios objective-c delegation

我有一个来自WebViewJavascriptBridge的包装类,它从JavaScript获取数据到Objective C,我需要将这些数据发送到它的扩展或其他类以获得适当的类,也从下到上我需要相同的从viewController更改方向更改方向,然后通知我的OrientationHandler类,然后EventManager然后,CommunicationManager并通知该桥类。

这是要启动的桥类代码

[self.bridge registerHandler:@"callHandler" handler:^(id data, WVJBResponseCallback responseCallback){
            [[CommunicationManager sharedInstance] initWithActionRequest:data];
            responseCallback(@200);
        }];

这里我的CommunicationManager选择需要加载的类..

-(BOOL)initWithActionRequest:(id)request {
    if ([request isKindOfClass:[NSDictionary class]]) {
        NSDictionary* requestType = (NSDictionary*)request;
        NSAssert((requestType != nil), @"request dictionary is nill");

        NSArray* params = [requestType[@"eventType"] componentsSeparatedByString:@"."];
        NSAssert(([params count] == 3), @"params array is nill");

        if ([params[0] isEqualToString:@"DeviceManager"]) {
            DeviceManager* deviceManager = [[DeviceManager alloc] initWithDeviceManagerRequestType:requestType];
            deviceManager.serviceName = params[1];
            deviceManager.serviceAction = params[2];
            [deviceManager performActionBasedOnRequest];
            return YES;

        } else if ([params[0] isEqualToString:@"EventManager"]) {
            EventManager* eventManager = [[EventManager alloc] initWithEventManagerRequestType:requestType];
            eventManager.serviceName = params[1];
            eventManager.serviceAction = params[2];
            [eventManager performEventBasedOnRequest];
            return YES;
        }
    }
    return NO;
}

然后我的DeviceManager类执行需要启动的服务

-(BOOL)performActionBasedOnRequest {
    if ([_serviceName isEqualToString:@"SipHandler"]) {

        SipHandler* sipHandler = [[SipHandler alloc] init];
        [sipHandler startPJSIPWithOptions:nil];
        return YES;

    } else {

    }
    return NO;
}

然后最后我的服务类SipHandler加载并运行方法

-(BOOL)startPJSIPWithOptions:(NSDictionary *)options {
    startPjsip(CLIENT_NAME, SERVER_HOST);
    return YES;
}

我对如何以有效的方式传输数据感到困惑?

0 个答案:

没有答案