JSPatch 使用Demo

来源:互联网 发布:三菱q系列编程手册 pdf 编辑:程序博客网 时间:2024/06/15 14:36
defineClass("AllControlViewController", {
            //instance method definitions
            ///ROOT_URL_STR 问题  强制转换问题
            ///@selector  直接使用字符串
            ///block中使用self   var sel = self;
            ///代码中包含_的变量   需要用__代替
            ///intValue()   需要用js的转换方式   parseInt

            ///变量比较      isEqual()

           ///获取成员变量  var data = self.valueForKey("_data")
           ///   基础问题:https://github.com/bang590/JSPatch/wiki

            logoutThroughServer: function() {
            
            Unity.addLoadingView_andLoadingTitle(self.view(), "正在哈哈,请稍候...");
            var manager = AFHTTPRequestOperationManager.manager();
            var sel = self;
            manager.POST_parameters_success_failure(NSString.stringWithFormat("%@/User/Logout", "http://xxxxxxxx"), {}, block('AFHTTPRequestOperation*,id', function(operation, responseObject) {
                                                                                                                                         
                                                                                                                                         Unity.removeLoadingView(sel.view());
                                                                                                                                         
                                                                                                                                         if (parseInt(responseObject.objectForKey("status")) == 0) {
                                                                                        {
                                                                                                                                         //退出登录需要重新获取clientid
                                                                                                                                         //                [GeTuiSdk enterBackground];
                                                                                                                                         
                                                                                                                                         //把登录状态置为0
                                                                                                                                         NSUserDefaults.standardUserDefaults().setValue_forKey("0", NSString.stringWithFormat("%@%", "APP_LOGIN_SUCESS_SVAE_MSG", Unity.getCurrentVersion()));
                                                                                                                                         NSUserDefaults.standardUserDefaults().setValue_forKey("0", "APP_LOGIN_USER_CURRENT_LOGIN_ID");
                                                                                                                                         
                                                                                                                                         //                [APP_USERDEFAULTS setValue:"0" forKey:[NSString stringWithFormat:"%@%", [AppDelegate getInstance].currentLoginID(), USER_SET_NOTIFY_ON_OFF]];
                                                                                                                                         
                                                                                                                                         UIApplication.sharedApplication().cancelAllLocalNotifications();
                                                                                                                                         
                                                                                                                                         NSNotificationCenter.defaultCenter().removeObserver_name_object(sel, "REFRESH_HOME_SCROLLVIEW", null);
                                                                                                                                         
                                                                                                                                         NSNotificationCenter.defaultCenter().removeObserver(AppDelegate.getInstance().allControlViewController());
                                                                                                                                         
                                                                                                                                         //判断如果蓝牙连接  取消连接
                                                                                                                                         if (AppDelegate.getInstance().blueManager().bleModel().bleManager().isConnected()) {
                                                                                                                                         
                                                                                                                                         var p = AppDelegate.getInstance().connectedPeripheral();
                                                                                                                                         
                                                                                                                                         AppDelegate.getInstance().disconnectPeripheral(p);
                                                                                                                                         }
                                                                                                                                         
                                                                                                                                         //清空必要的数据
                                                                                                                                         AppDelegate.getInstance().selectedUserIdArr().removeAllObjects();
                                                                                                                                         
                                                                                                                                         var rootNav =  AppDelegate.getInstance().window().rootViewController();
                                                                                                                                         
                                                                                                                                         if (rootNav.viewControllers().firstObject().isEqual(sel)) {
                                                                                                                                         
                                                                                                                                         var lvc = LoginViewController.alloc().init();
                                                                                                                                         
                                                                                                                                         var rootNav = UINavigationController.alloc().initWithRootViewController(lvc);
                                                                                                                                         
                                                                                                                                         AppDelegate.getInstance().window().setRootViewController(rootNav);
                                                                                                                                         
                                                                                                                                         rootNav.setNavigationBarHidden(true);
                                                                                                                                         
                                                                                                                                         return;
                                                                                                                                         }
                                                                                                                                         
                                                                                                                                         //退出到登录界面
                                                                                                                                         sel.navigationController().popToRootViewControllerAnimated(YES);
                                                                                                                                         }
                                                                                                                                         
                                                                                                                                         } else if (parseInt(responseObject.objectForKey("status")) == 3) {
                                                
                                                                                                                                         NSNotificationCenter.defaultCenter().addObserver_selector_name_object(sel, "logoutThroughServer", "RE_LOGIN_NOTIFY_NAME", null);
                                                                                                                                         
                                                                                                                                         Unity.reLoginTheApp(sel);
                                                                                                                                         } else {
                                                
                                                                                                                                         Unity.showSystemAlertWithMessage_andViewController(responseObject.objectForKey("error_message"), null);
                                                                                                                                         }
                                                                                                                                         }), block('AFHTTPRequestOperation*,NSError*', function(operation, error) {
                                                                                                                                                   
                                                                                                                                                   Unity.removeLoadingView(sel.view());
                                                                                                                                                   
                                                                                                                                                   Unity.showTheErrorWhenNetworkConnetFailed(sel);
                                                                                                                                                   }));
            
            }
            });
0 0
原创粉丝点击