zoukankan      html  css  js  c++  java
  • 第45月第28天 加载so库 iOS打包framework

    1.

    - (void)runtimePlay{
        // 获取音乐资源路径
        NSString *path = [[NSBundle mainBundle] pathForResource:@"rain" ofType:@"mp3"];
        // 加载库到当前运行程序
        void *lib = dlopen("/System/Library/Frameworks/AVFoundation.framework/AVFoundation", RTLD_LAZY);
        if (lib) {
            // 获取类名称
            Class playerClass = NSClassFromString(@"AVAudioPlayer");
            // 获取函数方法
            SEL selector = NSSelectorFromString(@"initWithData:error:");
            // 调用实例化对象方法
            _runtime_Player = [[playerClass alloc] performSelector:selector withObject:[NSData dataWithContentsOfFile:path] withObject:nil];
            // 获取函数方法
            selector = NSSelectorFromString(@"play");
            // 调用播放方法
            [_runtime_Player performSelector:selector];
            NSLog(@"动态加载播放");
        }

    https://www.jianshu.com/p/f931ff3b5d21

    #include <unistd.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/types.h>
    #include <dlfcn.h> /* 必须加这个头文件 */
    #include <assert.h>
     
    int main(int argc, char *argv[])
    {
        printf("come in
    ");
     
        void *handler = dlopen("libtest.so", RTLD_NOW);

          printf("dlopen - %sn", dlerror());  

    
        assert(handler != NULL);
        
        void (*pTest)(int);
        pTest = (void (*)(int))dlsym(handler, "add");
        
        (*pTest)(10);
     
        dlclose(handler);
        
        printf("go out
    ");
        return 0;
    }

    编译so库

    ##### 在模拟器下编译
    xcrun -sdk iphonesimulator clang -o libtest.so -shared -fPIC test.c
    
    #在真机下编译
    xcrun -sdk iphoneos clang -o libtest.so -shared -fPIC test.c


    //gcc -o libtest.so -shared -fPIC test.c

    #include <stdio.h>
     
    #ifdef __cplusplus
    extern "C"{
        
    #endif
        
    void add(int num)
    {
        printf("*****************************************
    ");
        printf("This is ok, the number is okay. %d
    ", num);
        printf("*****************************************
    ");
    }
     
     
    #ifdef __cplusplus
        }
        
    #endif

    https://blog.csdn.net/skwaityou/article/details/9098297

    2.iOS打包framework

    设置bitcode

    开启bitcode的前提,第三方库,支持bitcode编译才行。

    TARGETS->项目->Build Settings 搜索 other c flags 添加-fembed-bitcode

    https://67zz.cn/archives/677

  • 相关阅读:
    java web 自定义的权限框架
    java web 中 读取windows图标并显示
    apache httpclient
    Gson json解析工具
    org.apache.commons
    ehcache 缓存管理工具
    springmvc集成Freemarke配置的几点
    SaltStack与ZeroMQ(二)
    Python中的__init__和__new__介绍
    TCP 介绍
  • 原文地址:https://www.cnblogs.com/javastart/p/13202998.html
Copyright © 2011-2022 走看看