寫在前面:對(duì)于開發(fā)企業(yè)級(jí)應(yīng)用的開發(fā)者而已,以資源文件的形式來加載動(dòng)態(tài)庫就顯得尤為重要然眼,因?yàn)椋o不同的客戶打不同的IPA包葵腹,里面的有些功能是不一樣高每,比如說有一個(gè)動(dòng)態(tài)庫是專門為一個(gè)客戶制定的屿岂,那么在給其他客戶打包時(shí)就不應(yīng)該把這個(gè)動(dòng)態(tài)庫打進(jìn)去。所以鲸匿,為了解決這個(gè)問題爷怀,我們可以使用下面的這種加載方式。
1.添加動(dòng)態(tài)庫到資源
277EFE9E-0FBC-4288-991E-5BD5914D15FA.png
237D411C-396B-4B9D-9355-829A45AF9053.png
然后带欢,選擇你剛才放在主工程目錄下的動(dòng)態(tài)庫运授。這時(shí)項(xiàng)目目錄下多了一個(gè)動(dòng)態(tài)庫。倘若你之前直接拖進(jìn)來時(shí)目錄下就已經(jīng)存在乔煞,請(qǐng)先右鍵刪除引用吁朦。
2.動(dòng)態(tài)加載動(dòng)態(tài)庫
直接上我項(xiàng)目中實(shí)際使用的代碼:
這個(gè)動(dòng)態(tài)庫主要實(shí)現(xiàn)的是一個(gè)視頻會(huì)議的功能
這個(gè)TBConfMeetingApi類是我處理這個(gè)創(chuàng)建會(huì)議和加入會(huì)議的一個(gè)工具類
.h文件
//
// TBConfMeetingApi.h
// Ecm
//
// Created by zengchunjun on 16/9/13.
//
//
#import <Foundation/Foundation.h>
#import "TBConfMeetingManager.h"
@interface TBConfMeetingApi : NSObject
+ (void)joinConfWithSiteName:(NSString*)siteName DisplayName:(NSString*)displayName andUserName:(NSString*)userName MeetingID:(NSString*)meetingID MeetingPwd:(NSString*)meetingPwd WithPortrait:(NSString*) portrait VC:(UIViewController*)vc shareCallBack:(TBConferenceShareCallback)shareCallBack;
+ (void)createConfWithSiteName:(NSString*)siteName DisplayName:(NSString *)displayName andUserName:(NSString*)userName HostPwd:(NSString*)hostPwd MeetingTopic:(NSString*)meetingTopic MeetingPwd:(NSString *)meetingPwd WithAutoAdjustVideoBitrate:(BOOL)autoAdjustVideoBitrate VC:(UIViewController *)vc createCallBack:(TBConferenceEnterCallback)createCallBack shareCallBack:(TBConferenceShareCallback)shareCallBack;
@end
.m文件
//
// TBConfMeetingApi.m
// Ecm
//
// Created by zengchunjun on 16/9/13.
//
//
#import "TBConfMeetingApi.h"
@implementation TBConfMeetingApi
// 初始化動(dòng)態(tài)庫,也就是加載動(dòng)態(tài)庫
+ (BOOL)initFramework
{
if ([[UIDevice currentDevice].systemVersion floatValue] < 8.0)
{
NSLog(@"%s",__func__);
return NO;
}
// 使用GCD一次性代碼來只加載一次動(dòng)態(tài)庫
static dispatch_once_t priOnceToken;
dispatch_once(&priOnceToken, ^
{
NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"TBConfMeeting.framework"];
NSError *err = nil;
NSBundle *bundle = [NSBundle bundleWithPath:path];
if ([bundle loadAndReturnError:&err])
{
NSLog(@"bundle load framework success.");
}
else
{
NSLog(@"bundle load framework err:%@", err);
}
});
return YES;
}
+ (void)createConfWithSiteName:(NSString*)siteName DisplayName:(NSString *)displayName andUserName:(NSString*)userName HostPwd:(NSString*)hostPwd MeetingTopic:(NSString*)meetingTopic MeetingPwd:(NSString *)meetingPwd WithAutoAdjustVideoBitrate:(BOOL)autoAdjustVideoBitrate VC:(UIViewController *)vc createCallBack:(TBConferenceEnterCallback)createCallBack shareCallBack:(TBConferenceShareCallback)shareCallBack
{
//#if !TARGET_IPHONE_SIMULATOR
// [[ConfWithVc shareInstance] createConfWithSiteName:siteName DisplayName:displayName andUserName:userName HostPwd:hostPwd MeetingTopic:meetingTopic MeetingPwd:meetingPwd WithAutoAdjustVideoBitrate:autoAdjustVideoBitrate VC:vc createCallBack:callBack];
//#endif
if (![self initFramework]) {
return ;
}
NSString *className = @"TBConfMeetingManager";
NSString *methodName = @"createConfWithSiteName:DisplayName:andUserName:HostPwd:MeetingTopic:MeetingPwd:WithAutoAdjustVideoBitrate:VC:createCallBack:shareCallBack:";
Class class = NSClassFromString(className);
NSMethodSignature *sig = [[class class] methodSignatureForSelector:NSSelectorFromString(methodName)];
if (sig)
{
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
if (invocation)
{
[invocation setTarget:class];
[invocation setSelector:NSSelectorFromString(methodName)];
[invocation setArgument:&siteName atIndex:2];
[invocation setArgument:&displayName atIndex:3];
[invocation setArgument:&userName atIndex:4];
[invocation setArgument:&hostPwd atIndex:5];
[invocation setArgument:&meetingTopic atIndex:6];
[invocation setArgument:&meetingPwd atIndex:7];
[invocation setArgument:&autoAdjustVideoBitrate atIndex:8];
[invocation setArgument:&vc atIndex:9];
[invocation setArgument:&createCallBack atIndex:10];
[invocation setArgument:&shareCallBack atIndex:11];
[invocation invoke];
const char *returnType = sig.methodReturnType;
int *result;
if(!strcmp(returnType, @encode(int)))
{
[invocation getReturnValue:&result];
}
// return result;
}
}
}
+ (void)joinConfWithSiteName:(NSString*)siteName DisplayName:(NSString*)displayName andUserName:(NSString*)userName MeetingID:(NSString*)meetingID MeetingPwd:(NSString*)meetingPwd WithPortrait:(NSString*) portrait VC:(UIViewController*)vc shareCallBack:(TBConferenceShareCallback)shareCallBack
{
//#if !TARGET_IPHONE_SIMULATOR
// [[ConfWithVc shareInstance] joinConfWithSiteName:siteName DisplayName:displayName andUserName:userName MeetingID:meetingID MeetingPwd:meetingPwd WithPortrait:nil VC:vc];
//#endif
if (![self initFramework]) {
return;
}
NSString *className = @"TBConfMeetingManager";
NSString *methodName = @"joinConfWithSiteName:DisplayName:andUserName:MeetingID:MeetingPwd:WithPortrait:VC:shareCallBack:";
Class class = NSClassFromString(className);
NSMethodSignature *sig = [[class class] methodSignatureForSelector:NSSelectorFromString(methodName)];
if (sig)
{
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
if (invocation)
{
[invocation setTarget:class];
[invocation setSelector:NSSelectorFromString(methodName)];
[invocation setArgument:&siteName atIndex:2];
[invocation setArgument:&displayName atIndex:3];
[invocation setArgument:&userName atIndex:4];
[invocation setArgument:&meetingID atIndex:5];
[invocation setArgument:&meetingPwd atIndex:6];
[invocation setArgument:&portrait atIndex:7];
[invocation setArgument:&vc atIndex:8];
[invocation setArgument:&shareCallBack atIndex:9];
[invocation invoke];
}
}
}
@end