SparkDev97 / libSparkAppList

Do What The F*ck You Want To Public License
25 stars 8 forks source link

Getting AppList with handler: Handler block not run #5

Closed BeckettOBrien closed 4 years ago

BeckettOBrien commented 4 years ago

I recently switched from AppList to libSparkAppList because AppList had too many features that I didn't need. I attempted to get an NSArray of SparkAppItems using

[[[NSClassFromString(@"SparkAppList") alloc] init] getAppList:^(NSArray* apps){
        RLog(@"AppList: %@", apps);
}];

inside of my viewDidLoad for my preferences list controller. But I have found that the handler block is never being run. I am not %100 sure that this is the proper usage of getAppList but I could not find any examples for it, so this was my best attempt. Is this not the proper usage or is there something else wrong, like improper installation or a bug? Thank you!

SparkDev97 commented 4 years ago

The instance of SparkAppList may be getting dereferenced before it can return. Try declare it before the block first.

Also, make sure you have installed the latest version on the device from my repo.

I’m also not sure why you are using NSClassFromString - that’s not necessary if you properly added the library to your make file and added the header.

BeckettOBrien commented 4 years ago

The issue persists when using:

SparkAppList* appList = [[NSClassFromString(@"SparkAppList") alloc] init];
[appList getAppList:^(NSArray* apps){
    RLog(@"APPS: %@", apps);
}];

For some reason, NSClassFromString has been necessary for almost all calls to classes.

SparkDev97 commented 4 years ago

It’s not necessary at all, it means you aren’t linking the library properly. That’s why it won’t be working as the library isn’t actually getting loaded. Make sure you follow the instructions, include the library in the make file, include the header, and try running a make clean. If you’re calling it from your prefs bundle, make sure it’s in the makefile for the prefs bundle.

BeckettOBrien commented 4 years ago

Okay, It is working perfectly now. I had to also add it to the libraries section of my preferences makefile as well. Thank you for the help!