mirror of
https://github.com/YPLiang19/Mango
synced 2025-07-07 21:55:49 +00:00
Add WebKit And Block @Signature Example Case
This commit is contained in:
@ -9,6 +9,8 @@
|
||||
/* Begin PBXBuildFile section */
|
||||
89201FC727DA04C500A8AEA0 /* SomClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 89201FC627DA04C500A8AEA0 /* SomClass.m */; };
|
||||
8977D885224CC9070048A954 /* demo.mg in Resources */ = {isa = PBXBuildFile; fileRef = 89FC7DA9224C047700AFC0AC /* demo.mg */; };
|
||||
898CAAA12BEA1B7000CD0DCB /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 898CAAA02BEA1B6F00CD0DCB /* WebKit.framework */; };
|
||||
898CAAA42BEA1BBE00CD0DCB /* WebKitViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 898CAAA32BEA1BBE00CD0DCB /* WebKitViewController.m */; };
|
||||
899672BC224C02DC00C7DACB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 899672BB224C02DC00C7DACB /* Assets.xcassets */; };
|
||||
899672BF224C02DC00C7DACB /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 899672BD224C02DC00C7DACB /* LaunchScreen.storyboard */; };
|
||||
899672C2224C02DC00C7DACB /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 899672C1224C02DC00C7DACB /* main.m */; };
|
||||
@ -24,6 +26,9 @@
|
||||
0EDFFE948A3B02594E2D1D61 /* Pods-MangoFixDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MangoFixDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-MangoFixDemo/Pods-MangoFixDemo.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
89201FC527DA04C500A8AEA0 /* SomClass.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SomClass.h; sourceTree = "<group>"; };
|
||||
89201FC627DA04C500A8AEA0 /* SomClass.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SomClass.m; sourceTree = "<group>"; };
|
||||
898CAAA02BEA1B6F00CD0DCB /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
|
||||
898CAAA22BEA1BBE00CD0DCB /* WebKitViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebKitViewController.h; sourceTree = "<group>"; };
|
||||
898CAAA32BEA1BBE00CD0DCB /* WebKitViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WebKitViewController.m; sourceTree = "<group>"; };
|
||||
899672AF224C02DB00C7DACB /* MangoFixDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MangoFixDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
899672BB224C02DC00C7DACB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
899672BE224C02DC00C7DACB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||
@ -48,6 +53,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
898CAAA12BEA1B7000CD0DCB /* WebKit.framework in Frameworks */,
|
||||
BC32E13D2C11D1E1A9D7B3AB /* libPods-MangoFixDemo.a in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@ -58,6 +64,7 @@
|
||||
6952C940E97417B89B104D8C /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
898CAAA02BEA1B6F00CD0DCB /* WebKit.framework */,
|
||||
F2627AE79A14DF539C2D1C2F /* libPods-MangoFixDemo.a */,
|
||||
);
|
||||
name = Frameworks;
|
||||
@ -102,6 +109,8 @@
|
||||
89FC7DA1224C046800AFC0AC /* SuperMyController.m */,
|
||||
89FC7DA0224C046700AFC0AC /* ViewController.h */,
|
||||
89FC7DA3224C046800AFC0AC /* ViewController.m */,
|
||||
898CAAA22BEA1BBE00CD0DCB /* WebKitViewController.h */,
|
||||
898CAAA32BEA1BBE00CD0DCB /* WebKitViewController.m */,
|
||||
89201FC527DA04C500A8AEA0 /* SomClass.h */,
|
||||
89FC7DAE224C048600AFC0AC /* Main.storyboard */,
|
||||
89201FC627DA04C500A8AEA0 /* SomClass.m */,
|
||||
@ -215,6 +224,7 @@
|
||||
89FC7DAD224C047800AFC0AC /* AppDelegate.m in Sources */,
|
||||
89201FC727DA04C500A8AEA0 /* SomClass.m in Sources */,
|
||||
89FC7DA6224C046800AFC0AC /* CustomView.m in Sources */,
|
||||
898CAAA42BEA1BBE00CD0DCB /* WebKitViewController.m in Sources */,
|
||||
89FC7DA7224C046800AFC0AC /* SuperMyController.m in Sources */,
|
||||
89FC7DA8224C046800AFC0AC /* ViewController.m in Sources */,
|
||||
);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#import <WebKit/WebKit.h>
|
||||
#import <objc/runtime.h>
|
||||
#import "SomClass.h"
|
||||
#import "WebKitViewController.h"
|
||||
|
||||
NSString *nativeNSString = @"nativeNSString value";
|
||||
|
||||
@ -161,6 +162,14 @@ static NSString * const cellIdentifier = @"cell";
|
||||
case 19:
|
||||
[self nativeGlobalVariableAccess];
|
||||
break;
|
||||
case 20: {
|
||||
[self printBlockSignature];
|
||||
break;
|
||||
}
|
||||
case 21: {
|
||||
[self webkitExample];
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -170,7 +179,7 @@ static NSString * const cellIdentifier = @"cell";
|
||||
- (NSArray *)titles{
|
||||
if (_titles == nil) {
|
||||
_titles = @[@"顺序语句示例",@"if语句示例",@"switch语句示例",@"for语句示例",@"forEach语句示例",@"while语句示例",
|
||||
@"do while语句示例",@"block语句示例",@"参数传递示例",@"结构体传参示例",@"返回值示例",@"创建自定义ViewController",@"替换类方式示例",@"调用原始实现示例",@"条件注解示例",@"GCD示例",@"静态变量和取地址运算符示例",@"C函数变量示例", @"teypedef 示例", @"测试访问Native 全局变量"];
|
||||
@"do while语句示例",@"block语句示例",@"参数传递示例",@"结构体传参示例",@"返回值示例",@"创建自定义ViewController",@"替换类方式示例",@"调用原始实现示例",@"条件注解示例",@"GCD示例",@"静态变量和取地址运算符示例",@"C函数变量示例", @"teypedef 示例", @"测试访问Native 全局变量", @"打印block signature", @"WebKit 示例"];
|
||||
}
|
||||
return _titles;
|
||||
}
|
||||
@ -257,4 +266,81 @@ static NSString * const cellIdentifier = @"cell";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum {
|
||||
BLOCK_DEALLOCATING = (0x0001),
|
||||
BLOCK_REFCOUNT_MASK = (0xfffe),
|
||||
BLOCK_CREATED_FROM_MFGO = (1 << 23),
|
||||
BLOCK_NEEDS_FREE = (1 << 24),
|
||||
BLOCK_HAS_COPY_DISPOSE = (1 << 25),
|
||||
BLOCK_HAS_CTOR = (1 << 26),
|
||||
BLOCK_IS_GC = (1 << 27),
|
||||
BLOCK_IS_GLOBAL = (1 << 28),
|
||||
BLOCK_USE_STRET = (1 << 29),
|
||||
BLOCK_HAS_SIGNATURE = (1 << 30)
|
||||
};
|
||||
|
||||
|
||||
struct MFSimulateBlock {
|
||||
void *isa;
|
||||
int flags;
|
||||
int reserved;
|
||||
void *invoke;
|
||||
struct MFGOSimulateBlockDescriptor *descriptor;
|
||||
void *wrapper;
|
||||
};
|
||||
|
||||
struct MFGOSimulateBlockDescriptor {
|
||||
//Block_descriptor_1
|
||||
struct {
|
||||
size_t reserved;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
//Block_descriptor_2
|
||||
struct {
|
||||
// requires BLOCK_HAS_COPY_DISPOSE
|
||||
void (*copy)(void *dst, const void *src);
|
||||
void (*dispose)(const void *);
|
||||
};
|
||||
|
||||
//Block_descriptor_3
|
||||
struct {
|
||||
// requires BLOCK_HAS_SIGNATURE
|
||||
const char *signature;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
- (void)printBlockSignature {
|
||||
|
||||
// define your block
|
||||
id block = ^id (int, long, short) {
|
||||
return nil;
|
||||
};
|
||||
|
||||
|
||||
struct MFSimulateBlock *blockRef = (__bridge struct MFSimulateBlock *)block;
|
||||
int flags = blockRef->flags;
|
||||
|
||||
if (flags & BLOCK_HAS_SIGNATURE) {
|
||||
void *signatureLocation = blockRef->descriptor;
|
||||
signatureLocation += sizeof(size_t);
|
||||
signatureLocation += sizeof(size_t);
|
||||
|
||||
if (flags & BLOCK_HAS_COPY_DISPOSE) {
|
||||
signatureLocation += sizeof(void(*)(void *dst, void *src));
|
||||
signatureLocation += sizeof(void (*)(void *src));
|
||||
}
|
||||
const char *signature = (*(const char **)signatureLocation);
|
||||
NSLog(@"%s", signature);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)webkitExample {
|
||||
[self.navigationController pushViewController:[[WebKitViewController alloc] init] animated:YES];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
17
MangoFixDemo/MangoFixDemo/WebKitViewController.h
Normal file
17
MangoFixDemo/MangoFixDemo/WebKitViewController.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// WebKitViewController.h
|
||||
// MangoFixDemo
|
||||
//
|
||||
// Created by Tianyu Xia on 2024/5/7.
|
||||
// Copyright © 2024 yongpengliang. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WebKitViewController : UIViewController
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
23
MangoFixDemo/MangoFixDemo/WebKitViewController.m
Normal file
23
MangoFixDemo/MangoFixDemo/WebKitViewController.m
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// WebKitViewController.m
|
||||
// MangoFixDemo
|
||||
//
|
||||
// Created by Tianyu Xia on 2024/5/7.
|
||||
// Copyright © 2024 yongpengliang. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WebKitViewController.h"
|
||||
#import <WebKit/WebKit.h>
|
||||
|
||||
@interface WebKitViewController () <WKNavigationDelegate>
|
||||
|
||||
@end
|
||||
|
||||
@implementation WebKitViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
|
||||
@end
|
@ -371,3 +371,25 @@ class SomClass2 : SomClass1 {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class WebKitViewController : UIViewController {
|
||||
|
||||
- (void)viewDidLoad {
|
||||
super.viewDidLoad();
|
||||
|
||||
self.view.backgroundColor = UIColor.redColor();
|
||||
WKWebView *webView = WKWebView.alloc().initWithFrame:(self.view.bounds);
|
||||
self.view.addSubview:(webView);
|
||||
webView.navigationDelegate = self;
|
||||
NSURL *url = NSURL.URLWithString:(@"https://www.baidu.com");
|
||||
NSURLRequest *request = NSURLRequest.requestWithURL:(url);
|
||||
webView.loadRequest:(request);
|
||||
}
|
||||
|
||||
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(@Signature("v16@?0q8") Block)decisionHandler {
|
||||
NSLog(@"decidePolicyForNavigationAction");
|
||||
int WKNavigationActionPolicyAllow = 1;
|
||||
decisionHandler(WKNavigationActionPolicyAllow);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user