nsbundle

IOS 之 NSBundle 使用

别说谁变了你拦得住时间么 提交于 2019-12-11 10:58:21
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> IOS开发的时候,经常看到这样的代码, [[NSBundle mainBundle] pathForResource:@"someFileName" ofType:@"yourFileExtension"]; [YourViewController initWithNibName:"YourViewController" bundle:nil]; 一开始还不是很理解,通过google,慢慢的知道bundle在ios中的作用。 Bundle是什么呢?bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in). 对应bundle,cocoa提供了类NSBundle.bundle中的有些资源可以本地化.例如,对于foo.nib,我们可以有两个版本: 一个针对英语用户,一个针对法语用户. 在bundle中就会有两个子目录:English.lproj和French.lproj,我们把各自版本的foo.nib文件放到其中. 当程序需要加载foo.nib文件时,bundle会自动根据所设置的语言来加载. //在程序中获得main bundle NSBundle bundle = [NSBundle mainBundle]; /

Mac App Store - can't save a file

只谈情不闲聊 提交于 2019-12-11 08:04:48
问题 Are there any restrictions as far as saving files when you distribute an app over the Mac App Store? If I compile and run my app from my computer it works fine - it saves the configuration. However the version that was downloaded over the Mac App Store is not saving the configuration. I don't even see the config file. Anyone knows what is going on? This is the code that saves the config: -(void)saveConfig:(id)plist { NSString *path = [[[NSBundle mainBundle] resourcePath]

iPhone pathForResource vs bundlePath

夙愿已清 提交于 2019-12-11 04:29:36
问题 I want to use pathForResource, but it doesn't look like it will create the path if one doesn't exist. Therefore I'm trying to create one manually by doing the following: NSString *path = [NSString stringWithFormat:@"%@/%@.plist",[[NSBundle mainBundle] bundlePath],@"myFileName"]; I'm creating files dynamically, so I need to access them after I have Build and Run the application. But it puts the project in a unique id folder so the path comes out to something like: /Users/RyanJM/Library

Save/Copy a file from Bundle to Desktop using NSSavePanel

余生长醉 提交于 2019-12-11 03:18:48
问题 I’m creating a macOS app which ships with some .zip files within its Bundle directory. Users should be able to save these files from my app to a custom directory. I found NSSavePanel and thought it is the right approach — that’s what I have so far: @IBAction func buttonSaveFiles(_ sender: Any) { let savePanel = NSSavePanel() let bundleFile = Bundle.main.resourcePath!.appending("/MyCustom.zip") let targetPath = NSHomeDirectory() savePanel.directoryURL = URL(fileURLWithPath: targetPath

How can I include a txt file in an Xcode project?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 19:45:43
问题 I added a file "IntegerArray.txt" as follows, first I went to File -> Add file to "project name", I selected my file and it was copied into the root folder of my project, the same one that contains the .xcodeproj file. Then I clicked on my project's .xcodeproj file in Xcode, after which I went to Build Phases -> Copy Files -> "IntegerArray.txt", however when I build my project, the following code doesn't work let bundle = NSBundle.mainBundle() let path = bundle.pathForResource("IntegerArray",

Getting a nil path from NSBundle

风格不统一 提交于 2019-12-10 17:42:01
问题 I have created a new folder in my project in which I have copied an image (called "io.jpg"). I also have checked on build phases -> copy bundle resources and the file is there. So I am trying to get the path of this image: NSBundle* bundle=[NSBundle mainBundle]; NSString* path=[bundle pathForResource: @"io" ofType: @"jpg"]; NSLog(@"%@",path); But it prints (null), I also have tried this way: NSBundle* bundle=[NSBundle mainBundle]; NSString* path=[bundle pathForImageResource: @"io"]; NSLog(@"%

UILocalNotification custom sound

时光总嘲笑我的痴心妄想 提交于 2019-12-09 03:06:24
问题 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

Accessing images from nsbundle

时光怂恿深爱的人放手 提交于 2019-12-08 08:26:13
问题 I have a framework which is trying to access xib's and images from a bundle. I am able to access the xib fine but unable to load the images in UIImageView. I even check if the file exists and the console output is yes... Any idea how to load the image? Code to load xib in the framework viewcontroller file self = [super initWithNibName:@"ViewController_iPad" bundle:[NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"MyBundle" ofType:@"bundle"]]]; Code to load images - (void)

Sqlite3 from Bundle Resources in iOS

做~自己de王妃 提交于 2019-12-08 08:12:50
问题 Hi I'm planning to add a static SQLite3 from my projects resource folder but I dont know if I'm doing it correctly. so far here's my progress... Created SQLite3 Database from SQLite Database Browser Copied Sqlite3 Database to my project folder Added network.db to my project resource folder and now I don't know where to go next.. I hope someone can help me with my problem. 回答1: If you are modifying your database at run time (i.e. you are inserting, deleting or updating records), you need to

Need to make a DLC “packet” system for my iOS game

十年热恋 提交于 2019-12-08 04:51:07
问题 I'm developing a game for iOS and I need to make a system to download "packs" after the player bought them with In App Purchases. I've search on the internet for a method like using a bundle, or just using web services, but I really don't know which one is the best. Let me be specific: in one pack the player has between 1-3 sprites, 1-2 music files, and 1-3 backgrounds. So what I need to do is download that "pack" and store it as "purchased". What methods would be the most reusable and