注意: App动态加载动态库dylib不能通过App Store上架审核
就可以吧带有功能的dylib放在服务器上 在线更新 省去重新打包签名分发安装 1.如hook某个App 2.如游戏辅助 3.比如有新功能 放到服务器 APP端启动在线更新即可 4.好处:动态更新动态加载 时间灵活 可加载可卸载
-
(BOOL)dylib { //提前吧OsGods.Cn.dylib放到沙盒目录 由于iOS限制 未越狱无法导入沙盒目录 最好放到服务器远程下载 //从服务器上下载iOsGods.Cn.dylib保存到沙盒目录Documents、Library、tmp (方法自己写哦!)
//获取并调用沙盒目录中下载好的的iOsGods.Cn.dylib动态库 NSString *frameworkPath = [NSString stringWithFormat:@"%@/Documents/iOsGods.Cn.dylib",NSHomeDirectory()]; libHandle = NULL; //获取并调用沙盒目录中的iOsGods.Cn.dylib动态库 libHandle = dlopen([frameworkPath cStringUsingEncoding:NSUTF8StringEncoding], RTLD_NOW); NSString *str = @"加载iOsGods.Cn失败!";
if (libHandle == NULL) { char *error = dlerror(); NSLog(@"3error: %s", error); } else { NSLog(@"加载iOsGods.Cn成功打印"); str = @"加载iOsGods.Cn成功"; //判断调用成功 这里可写成功后执行的功能
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:str message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; [alertView show];
}
#这是写在被调用iOsGods.Cn.dylib程序中的功能 #如:被调用的动态库.m 有个bsphp功能,被执行后打印 NSLog(@"调用bsphp成功"); #并且弹出提示框:这是luntan程序 #import "PiaoJin.h" #import <UIKit/UIKit.h>
@implementation PiaoJin
- (void)luntan{ NSLog(@"调用bsphp成功"); UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"这是luntan程序" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; [alertView show]; }
@end #这是写在被调用dylib程序中的功能
-
(BOOL)dyluntan{ Class piaoJinClass = NSClassFromString(@"PiaoJin");//这里的PiaoJin 是iOsGods.Cn.dylib程序中的声明 if(piaoJinClass){ //事先要知道有什么方法在这个iOsGods.Cn.dylib中 id object = [[piaoJinClass alloc] init]; //由于没有引入相关头文件故通过performSelector调用 [object performSelector:@selector(luntan)];//这里的luntan是 是iOsGods.Cn.dylib程序中的方法 }else { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"调用方法失败!" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; [alertView show];
} }