Monday, April 29, 2013

NSBundle builtInPlugInsPath example ios


builtInPlugInsPath

Returns the full pathname of the receiver's subdirectory containing plug-ins.
- (NSString *)builtInPlugInsPath
Return Value of [NSBundle builtInPlugInsPath]
The full pathname of the receiving bundle’s subdirectory containing plug-ins.
Discussion of [NSBundle builtInPlugInsPath]
This method returns the appropriate path for modern application and framework bundles. This method may not return a path for non-standard bundle formats or for some older bundle formats.
Example of [NSBundle builtInPlugInsPath]
#import <Cocoa/Cocoa.h>

@interface PluginPrincipalClass : NSObject
@end


#import "PluginPrincipalClass.h"

@implementation PluginPrincipalClass

- (NSInteger)getDownloadPercentage
{
    NSLog(@"getDownloadPercentage");
    return 10;
}

- (void)downloadSoftwareUpdate
{
     NSLog(@"downloadSoftwareUpdate");
}
@end

#import <Cocoa/Cocoa.h>

@interface ClassOne : NSObject
@end

#import "ClassOne.h"

@implementation ClassOne

- (void)ClassOneMethod
{
    NSLog(@"ClassOneMethod");
}    
@end

#import <Cocoa/Cocoa.h>

@interface ClassTwo : NSObject
@end

#import "ClassTwo.h"

@implementation ClassTwo

- (void)ClassTwoMethod
{
    NSLog(@"ClassTwoMethod");
}

@end

NSString *zStrPlugInsPath = [[NSBundle mainBundle] builtInPlugInsPath];
NSArray *zAryBundlePaths = [NSBundle pathsForResourcesOfType:@"plugin"
                                                 inDirectory:zStrPlugInsPath];
NSString * zStrPathToPlugin = [zAryBundlePaths lastObject];
NSBundle *znsBundlePlugin = [NSBundle bundleWithPath:zStrPathToPlugin];

// instantiate the principal class and call the method
Class zPrincipalClass = [znsBundlePlugin principalClass];
id zPrincipalClassObj = [[zPrincipalClass alloc]init];


NSInteger downloadPer = [zPrincipalClassObj getDownloadPercentage];

NSLog(@"downloadPer  = %ld",downloadPer);

[zPrincipalClassObj downloadSoftwareUpdate];