nsbundle

Cocoa - loadNibNamed:owner:topLevelObjects: from loaded bundle

﹥>﹥吖頭↗ 提交于 2019-12-01 08:38:29
In a document based Cocoa app, I am instantiating several objects (plugins) from external bundles using: - (NSMutableArray *)getPluginsOfType:(Class)type; { NSBundle *main = [NSBundle mainBundle]; NSArray *allPlugins = [main pathsForResourcesOfType:@"bundle" inDirectory:@"../PlugIns"]; NSMutableArray *availablePlugins = [NSMutableArray array]; for (NSString *path in allPlugins) { NSBundle *pluginBundle = [NSBundle bundleWithPath:path]; [pluginBundle load]; Class principalClass = [pluginBundle principalClass]; [availablePlugins addObject:principalClass]; } return availablePlugins; } Within each

Cocoa - loadNibNamed:owner:topLevelObjects: from loaded bundle

为君一笑 提交于 2019-12-01 07:19:55
问题 In a document based Cocoa app, I am instantiating several objects (plugins) from external bundles using: - (NSMutableArray *)getPluginsOfType:(Class)type; { NSBundle *main = [NSBundle mainBundle]; NSArray *allPlugins = [main pathsForResourcesOfType:@"bundle" inDirectory:@"../PlugIns"]; NSMutableArray *availablePlugins = [NSMutableArray array]; for (NSString *path in allPlugins) { NSBundle *pluginBundle = [NSBundle bundleWithPath:path]; [pluginBundle load]; Class principalClass = [pluginBundle

XCTest fails when calling [NSBundle mainBundle]

佐手、 提交于 2019-12-01 06:43:29
问题 I have some code that calls [NSBundle mainBundle] at some point, mainly to read/set preferences. When I unit test the method, the test fails because the test's mainBundle does not contain the file. This is a known issue, that Apple won't fix as they consider it is not a bug: the gist of their reply is that XCTest is working correctly by returning it’s own main bundle instead of the bundle of the test target. Previously our codebase was using a category override on NSBundle 's +mainBundle

Write in Main Bundle directory. Is it allowed?

守給你的承諾、 提交于 2019-12-01 04:58:38
问题 I was pretty sure that writing in the main Bundle isn't possible in iOS ... for example an operation like : NSString *path = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"]; .....something [xmlData writeToFile:path atomically:YES]; Why does the first example in Apple's documentation use this exact code? 回答1: The example is for OS X, which isn't quite as strict with permissions as iOS. I'd be surprised if you are able to do that for much longer (if you can at all now) in a Mac

UILocalNotification custom sound

蓝咒 提交于 2019-12-01 03:54:56
I have been searching for a solution for hours.. with absolutely zero luck. I set up a Local Notification: UILocalNotification *notif = [[cls alloc] init]; [dateComp setDay:j+1]; [dateComp setHour:[[time objectAtIndex:0] integerValue]+offset]; [dateComp setMinute:[[time objectAtIndex:1] integerValue]]; NSLog(@"Year: %i, Month: %i, Day: %i, Time:%i:%i\n",[dateComp year], [dateComp month], [dateComp day], [dateComp hour], [dateComp minute]); notif.fireDate = [gregorian dateFromComponents:dateComp]; notif.timeZone = [NSTimeZone defaultTimeZone]; notif.alertBody = [names objectAtIndex: k]; notif

How can I find the path to a file in an application bundle (NSBundle) using C?

∥☆過路亽.° 提交于 2019-11-30 19:42:16
Is there a C API for finding the path to a file in an application bundle? I know that this can be done in Objective-C with the following syntax. NSString *path = [[NSBundle mainBundle] pathForResource:@"MyImage" ofType:@"bmp"]; Is there a corresponding function that I can call from C or C++ code, as well? Chris Frederick After Mike K pointed me in the right direction , I was able to retrieve the path to a file in an application bundle with the following code. // Get a reference to the main bundle CFBundleRef mainBundle = CFBundleGetMainBundle(); // Get a reference to the file's URL CFURLRef

Getting bundle file references / paths at app launch

ぃ、小莉子 提交于 2019-11-30 16:53:53
Suppose I have an arbitrary set of files included in the Main App Bundle. I would like to fetch the file URLs for those at launch and store them somewhere. Is this possible using NSFileManager ? The documentation is unclear in that regard. Note: I only need the file URLs, I do not need to access the actual files. You can get the URL of a file in the main bundle using NSString *path = [[NSBundle mainBundle] pathForResource:@"SomeFile" ofType:@"jpeg"]; NSURL *url = [NSURL fileURLWithPath:path]; You can write this URL to, for example, a property list file in the Documents directory: NSString

Get the main app bundle from within extension

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 11:24:42
问题 Is it possible to get the containing app's NSBundle from within an app extension? I would like to get the main app's display name, not the extension's display name. 回答1: The +mainBundle method returns the bundle containing the "current application executable", which is a subfolder of your app when called from within an extension. This solution involves peeling off two directory levels from the URL of the bundle, when it ends in "appex". Objective-C NSBundle *bundle = [NSBundle mainBundle]; if

NSBundle - (not loaded yet) Error

血红的双手。 提交于 2019-11-30 05:39:39
问题 I am trying to get a strings file table for use with NSLocalizedStringFromTableInBundle. I am using this method: +(NSBundle*)getBundleForLang:(NSString*)lang{ //get the path to the bundle NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"localizable" ofType:@"strings" inDirectory:nil forLocalization:lang]; NSLog(@"bundlePath = %@",bundlePath); //load the bundle NSBundle *langBundle = [[NSBundle alloc] initWithPath:[bundlePath stringByDeletingLastPathComponent]]; NSLog(@

How can I find the path to a file in an application bundle (NSBundle) using C?

五迷三道 提交于 2019-11-30 04:42:30
问题 Is there a C API for finding the path to a file in an application bundle? I know that this can be done in Objective-C with the following syntax. NSString *path = [[NSBundle mainBundle] pathForResource:@"MyImage" ofType:@"bmp"]; Is there a corresponding function that I can call from C or C++ code, as well? 回答1: After Mike K pointed me in the right direction, I was able to retrieve the path to a file in an application bundle with the following code. // Get a reference to the main bundle