Bloggers learn WEEX also have a period of time, before the Demo is pure WEEx, is the introduction of all JS files in Xcode project, through the loading of local JS files to achieve the project, but there is only a VC, quite so embedded in the web app, of course, weex performance is much better. So next, the blogger will show you how to use WEEx JS file to achieve different VC interaction, as well as Xcode and WEEx interaction: 1. Customize the Module to implement the push method (navagator is definitely not available in such a project environment)

#import <Foundation/Foundation.h> #import <WeexSDK/WeexSDK.h> @interface WXEventModule : NSObject <WXModuleProtocol> @end #import "WXEventModule.h" #import "HomeBigViewController.h" @implementation WXEventModule @synthesize weexInstance; WX_EXPORT_METHOD(@selector(push:)) //WX_EXPORT_METHOD(@selector(pop)) //WX_EXPORT_METHOD(@selector(present:)) //WX_EXPORT_METHOD(@selector(dismiss)) // //WX_EXPORT_METHOD(@selector(postGlobalEvent::)) - (void)anotherOpenURL:(NSString *)url callback:(WXKeepAliveCallback)callback { callback(url,false); NSLog(@"call me"); } - (void)openURL:(NSString *)url { NSString *newURL = url; if ([url hasPrefix:@"//"]) { newURL = [NSString stringWithFormat:@"http:%@", url]; } else if (! [url hasPrefix:@"http"]) { // relative path newURL = [NSURL URLWithString:url relativeToURL:weexInstance.scriptURL].absoluteString; } UIViewController *controller = [[HomeBigViewController alloc] init]; ((HomeBigViewController *)controller).url = [NSURL URLWithString:newURL]; [[weexInstance.viewController navigationController] pushViewController:controller animated:YES]; } - (void)push:(NSString *)url { [self openURL:url]; }Copy the code

You can use the push method in WeeX, but you need to register the Module in Xcode’s Appdelegate:

// You can use the first name as you like. The back of the class name and the name of the class to agree [WXSDKEngine registerModule: @ "WXEventModule" withClass: NSClassFromString (@ "WXEventModule")];Copy the code

3. How to use the push method in WEEX

// This is a method in WEEx, WXEventModule is our registered name, Then pull the push method bigAction(index){console.log('will jump') weex.requiremodule ("WXEventModule").push(" homebig.js "); },Copy the code

You may have noticed that push is the name of a JS file. Yes, it is directly inserted into the file name of the JS file you want to jump to. If you need to pass a parameter, there are two ways:! Storage; !!) Add parameters to push, such as:

WX_EXPORT_METHOD(@selector(push:ids:)) - (void)push:(NSString *)url ids:(NSString *)ID {[self openURL:url]; } // If there are other native requirements, such interaction is no problem, but if there are all such js loading interface, or use storage, the data will affect the VC, see below;Copy the code

4. This is the highlight, how to write VC? It is impossible for us to have a single JS corresponding to a single VC, of course, this can also be written, but will be very troublesome, here divided into two cases:! All js file loading interface; !!) Weex JS interface, there are native interface; If some functions need to be implemented in the native interface and passed to the native interface, the above values are the most appropriate method, but if all the JS interface such values are meaningless, because you get the values from JS in the new VC and then pass the values to the already written JS interface, not to mention the implementation problems. In Xcode, because of the integration of the WEEX environment, it still supports storage, but only between weeX JS.

Here’s how to write the VC: all js are loaded with VC:

#import <UIKit/UIKit.h> @interface HomeBigViewController : UIViewController @property (nonatomic, strong) NSURL *url; @end #import "HomeBigViewController.h" #import <WeexSDK/WXSDKInstance.h> @interface HomeBigViewController () @property (nonatomic, strong) WXSDKInstance *instance; @property (nonatomic, strong) UIView *weexView; @property (nonatomic, assign) CGFloat weexHeight; @property (nonatomic, assign) CGFloat top; @end @implementation HomeBigViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.view.backgroundColor = [UIColor whiteColor]; if (! self.navigationController.navigationBar.hidden) { _top = CGRectGetMaxY(self.navigationController.navigationBar.frame); } else{ _top = CGRectGetMaxY([[UIApplication sharedApplication]statusBarFrame]); } _weexHeight = self.view.frame.size.height - _top; [self render]; } - (void)dealloc { [_instance destroyInstance]; } - (void)viewWillAppear:(BOOL)animated { [self.navigationController.navigationBar setHidden:YES]; [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; self.navigationController.navigationBar.barTintColor = [UIColor whiteColor]; self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor blueColor]}; [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault]; } - (void)render { _instance = [[WXSDKInstance alloc] init]; _instance.viewController = self; CGFloat width = self.view.frame.size.width; _instance.frame = CGRectMake(self.view.frame.size.width-width,_top, width, _weexHeight); __weak typeof(self) weakSelf = self; _instance.onCreate = ^(UIView *view) { [weakSelf.weexView removeFromSuperview]; weakSelf.weexView = view; [weakSelf.view addSubview:weakSelf.weexView]; UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, weakSelf.weexView); }; _instance.onFailed = ^(NSError *error) { NSLog(@"failed %@",error); }; _instance.renderFinish = ^(UIView *view) { NSLog(@"render finish"); }; _instance.updateFinish = ^(UIView *view) { NSLog(@"update Finish"); }; [_instance renderWithURL:_url options:@{@"bundleUrl": [NSString stringWithFormat:@"file://%@/bundlejs/components/",[NSBundle mainBundle].bundlePath]} data:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @endCopy the code

In addition to the description of the custom module, there is also a registration to load images, using SDWebImage3.7.5, the version is too high to find the method:

    [WXSDKEngine registerHandler:[WXImgLoaderDefaultImpl new] withProtocol:@protocol(WXImgLoaderProtocol)];
Copy the code

Another feature is the weeX extension, the native interface forward in WEEX, through the use of labels in WEEX, actually are not complex, you can see here: weex-project. IO /cn/guide/ex…

There is a Demo about this implementation for your reference, but in the swift writing method, at the beginning did not find, simply is egg, ADDRESS I sent for your reference: github.com/acton393/We…

Above, well, basically weex is entered into the door, the next question is encapsulation, style and understanding of the ES, here, you can write weex according to this way to access the iOS project inside, this is just a way, convenient for other primary processing, if you are confident pure weex no problem can also be directly with pure weex package.

Summary: blog writing here, the weeX learning path of the blogger also come to an end, if you have finished reading the blog weex aspects of the blogger, you have already entered the door, congratulations, you can start your weex development road. But this is not the end, there will be irregular updates in the future, the next step, due to the business of the company will be transferred to Huawei fast application development, maybe soon, about fast application pit and technical points of the blogger will start to update, welcome to read, learn together.