죄송합니다. 영어가 좋지 않지만, 분명히 제 질문을 설명하겠습니다. 나는 다운로드 동적 프레임 워크를 구현하고 우리의 '실내'응용 프로그램에로드하려고NSBundle이 동적 프레임 워크를 내릴 수 없습니다.
. (실내 응용 프로그램, 우리가 앱 스토어에 대해 상관하지 않기 때문에.) (이 article 참조)
다운로드, 부하 및 동적 인기구를 사용하는 것은 좋다! 그것은 잘 작동합니다.
그러나 언로드하려고 할 때 새로운 동적 프레임 워크 (동일한 프레임 워크 이름이지만 내부 클래스가 다릅니다.)를로드하려고합니다. (모든 이전 프레임 워크는 새 프레임 워크를로드하기 전에 언로드되고 삭제됩니다.)하지만 여전히 클래스는 오래되었습니다. 수업.
언로드 프레임 워크 코드 :
NSBundle *bundle = [NSBundle bundleWithPath:documentsPath];
result = [bundle unload]; // I use break point, it says unload MyFramework.framework.
[self removeBundleAndZip]; // It's just a function to remove bundle files.
그러나 여전히 클래스를 사용할 수 있습니다. 나는 클래스가 dealloc이라는 것을 확신한다 (나는 클래스 dealloc 일 때 그것을 출력한다.). 그리고 객관적인 C 런타임이이 클래스를 캐시 할 것 같아요.
그래서 나는 다른 기사 ( How to remove NSBundle cache)를 발견하고, 그와 같은 추가 :NSBundle *bundle = [NSBundle bundleWithPath:documentsPath];
result = [bundle unload]; // I use break point, it says unload MyFramework.framework.
if (FlushBundleCache(bundle)) {
NSLog(@" ** Success: flush bundle cache SUCCESS ...");
}
else{
NSLog(@" ** Faile: flush bundle cache FAIL! ");
}
[self removeBundleAndZip]; // It's just a function to remove bundle files.
세척 성공을하지만 여전히로드 및 언로드 낡은 후에 새로운 프레임 워크를 사용할 수 없습니다. (로드는 괜찮지 만 프레임 워크의 새 클래스가 아니라 이전 프레임 워크의 새 클래스가 아닙니다. 응용 프로그램을 다시 시작하면 새로운 프레임 워크가 사용됩니다. 응용 프로그램을 다시 시작하면로드되고로드됩니다.)
언로드하는 방법이 있습니까? 이전 프레임 워크를로드하고 새 것을로드하지만 응용 프로그램을 다시 시작하지 않습니까?
PS : 여기
NSString *documentsPath = [NSString stringWithFormat:@"%@/Documents/%@/%@",NSHomeDirectory() , @"frameworkFolder" , @"myDownloadFramework.framework"];
if ([[NSFileManager defaultManager] fileExistsAtPath:documentsPath]) {
NSError *error = nil;
NSBundle *bundle = [NSBundle bundleWithPath:documentsPath];
if ([bundle loadAndReturnError:&error]) {
if (error) {
NSLog(@"Fail: NSBundle load framework fail.(%@)" , error.description);
}
else{
NSLog(@"Success: NSBundle load framework success!");
result = YES;
}
}
else{
NSLog(@"Fail: NSBundle load framework fail.");
}
}
else{
NSLog(@"Fail: NSBundle load framework fail.(file not exist)");
}
다운로드 프레임 워크에
Class myClass = objc_getClass("MyClassInFramework");
사용하는 클래스 메서드
SEL myMethod = @selector(myMethodInClass);
if([myClass responseToSelector:myMethod]){
objc_msgSend(myClass , myMethod , nil);
}
PS 내 클래스를 사용 ... 내 부하 프레임 워크 코드입니다 : 우리 새로운 업데이트가 있으면 우리 앱을 항상 게시하는 것을 막으려 고하기 때문에이 작업을 수행해야합니다.
사과 프레임이 iOS 10 이후에 동적 프레임 워크를로드하는 방법을 차단한다고 생각합니다. 슬픈 :( –