0

Sorry I speak poor English, but I will descript my question clearly.

I am trying to implement download dynamic framework and load it in our 'InHouse' App.(see this article)(Because of InHouse app, we don't care about AppStore.)

Download , load and use dynamic framework is OK! It works fine.

But when I try to unload it and download new dynamic framework (The same framework name but different inside class.) to load it.(All old framework will unload and delete before load new one.) But the class still old class.

unload framework code :

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.

But it still can use the class. I pretty sure the class is dealloc (I print it when the class dealloc.). And I guess it's objective-C runtime to cache this class.

So I found another article(How to remove NSBundle cache), and I add it like that:

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.

Flush success but still can't load and use new framework after unload old ones. ( load is ok but still old class not new ones in framework, if I restart app, it will use new framework. That shows we download it and load if we restart App is ok. )

Is there any way to unload old framework and load new one's but not restarting App?

PS: Here is my load framework code...

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 )");
}

use my class which is in download framework

Class myClass = objc_getClass("MyClassInFramework");

use class method

SEL myMethod = @selector(myMethodInClass);
if( [myClass responseToSelector:myMethod] ){
    objc_msgSend( myClass , myMethod , nil );
}

PS: We need to do this because we want to prevent publish our App all the time if we have new update.

Community
  • 1
  • 1

1 Answers1

0

Maybe you should not use ARC in you framework.

I think the app still load the framework until you kill it.