NSBundle理解(绑定包)

bundle捆绑包/绑定包(bundle绑定包处于独立的硬件空间),Xcode工程师构建的可执行的项目工程的压缩产品软件包(ipa)本身也可视为某个绑定包(主绑定包mainBundle(主体研究对象方向))。主绑定包mainBundle包含可执行的逻辑规则代码指令和开发者注入的相关资源如图片资源/音频资源/视频资源等等。
结构层次概念体系NSBundle类用来定位可执行资源所处的位置,获取具体的可执行文件的位置而后加载进入内存中供CPU调用。NSBundle的使用仅限制于独立的绑定空间(对于独立的绑定空间可通过NSBundle概念实现操作(如executable可执行项目工程/dynamic动态库等可通过NSBundle概念研究))
NSBundle官方文档中可以看到:
Any executable can use a bundle object to locate resources, either inside an app‘s bundle or in a known bundle located elsewhere. You don’t use a bundle object to locate files in a container directory or in other parts of the file system.
使用NSBundle绑定对象来定位任何可执行文件包内资源。无论是在某个应用程序项目工程的软件包中还是在其他地方的已知集成包中。在容器目录或文件系统的其他部分,不能使用NSBundle对象来定位文件系统资源。
executable可执行包是运行时可执行包/DynamicLibrary动态库是运行时加载进入内存由CPU调用触发。
绑定包风格:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在iOS中定Unity的委托需要使用Unity提供的UnityBinding文件,该文件定义了Unity中的所有公共API,并提供了Objective-C接口,可以在iOS代码中使用。以下是一个简单的示例代码,演示如何在iOS中定Unity的委托: 首先,在Unity中创建一个C#脚本,用于定义需要定的委托方法。例如: ``` using UnityEngine; public class DelegateExample : MonoBehaviour { public delegate void OnButtonClickDelegate(string buttonName); public static OnButtonClickDelegate OnButtonClick; public void OnButtonClicked(string buttonName) { if (OnButtonClick != null) { OnButtonClick(buttonName); } } } ``` 在iOS中,需要使用UnityBinding文件中的方法来定委托。以下是一个示例代码,演示如何定上述的OnButtonClick委托: ``` #import "UnityInterface.h" #import "UnityAppController.h" @interface iOSUnityBridge : UnityAppController<UIApplicationDelegate> @end @implementation iOSUnityBridge - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { // Initialize Unity UnityInit([[[NSBundle mainBundle] bundlePath] UTF8String], "AppController", [self getUnityAppCommandLine]); // Add Unity view to the current view controller UIView* unityView = (__bridge UIView*)UnityGetGLView(); UIViewController* rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController; [rootViewController.view addSubview:unityView]; // Bind delegate UnitySendMessage("DelegateExample", "set_OnButtonClickDelegate", "iOSUnityBridge", 0); return YES; } - (void)onButtonClick:(const char*)buttonName { NSString* name = [NSString stringWithUTF8String:buttonName]; NSLog(@"Button clicked: %@", name); // Call Unity delegate UnitySendMessage("DelegateExample", "OnButtonClick", buttonName); } @end ``` 在上述代码中,UnitySendMessage函数用于调用Unity中的set_OnButtonClickDelegate方法,将iOS中的iOSUnityBridge类定到Unity的OnButtonClick委托上。然后,在onButtonClick方法中,调用UnitySendMessage函数,触发Unity的OnButtonClick委托。 需要注意的是,以上代码只是一个简单的示例,实际实现中还需要考虑更多的细节和异常情况。同时,UnityBinding文件中的方法和接口可能会随着Unity版本的不同而有所变化,需要根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HaiJunYa

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值