iphone Programming Glossary: mainbundle
Implementation of “Automatic Lightweight Migration” for Core Data (iPhone) http://stackoverflow.com/questions/2310216/implementation-of-automatic-lightweight-migration-for-core-data-iphone managedObjectModel if managedObjectModel nil return managedObjectModel NSString path NSBundle mainBundle pathForResource @ YOURDB ofType @ momd NSURL momURL NSURL fileURLWithPath path managedObjectModel NSManagedObjectModel..
Difference between [UIImage imageNamed…] and [UIImage imageWithData…]? http://stackoverflow.com/questions/316236/difference-between-uiimage-imagenamed-and-uiimage-imagewithdata There's 2 easy ways to do this UIImage imageNamed fullFileName or NSString fileLocation NSBundle mainBundle pathForResource fileName ofType extension NSData imageData NSData dataWithContentsOfFile fileLocation..
Play sound on iPhone even in silent mode http://stackoverflow.com/questions/3740528/play-sound-on-iphone-even-in-silent-mode sounds like this probably an instance variable AVAudioPlayer player NSString path NSBundle mainBundle pathForResource... NSURL url NSURL fileURLWithPath path player AVAudioPlayer alloc initWithContentsOfURL..
Getting current device language in iOS? http://stackoverflow.com/questions/3910244/getting-current-device-language-in-ios note that this list does not indicate what language the app is actually running in the NSBundle mainBundle object determines that at launch and knows that information People interested in app language take a..
iOS SDK - Programmatically generate a PDF file http://stackoverflow.com/questions/4362734/ios-sdk-programmatically-generate-a-pdf-file to from design time coordinates . In code I load the view UIView loadTemplate NSArray nib NSBundle mainBundle loadNibNamed @ ReportTemplate owner self options nil for id view in nib if view isKindOfClass UIView..
Getting a list of files in a directory with a glob http://stackoverflow.com/questions/499673/getting-a-list-of-files-in-a-directory-with-a-glob directory. I'm currently stuck with something along the lines of NSString bundleRoot NSBundle mainBundle bundlePath NSArray dirContents NSFileManager defaultManager directoryContentsAtPath bundleRoot ..and.. can achieve this pretty easily with the help of NSPredicate like so NSString bundleRoot NSBundle mainBundle bundlePath NSFileManager fm NSFileManager defaultManager NSArray dirContents fm contentsOfDirectoryAtPath.. fltr If you need to do it with NSURL instead it looks like this NSURL bundleRoot NSBundle mainBundle bundleURL NSArray dirContents fm contentsOfDirectoryAtURL bundleRoot includingPropertiesForKeys @ options..
iPhone Facebook Video Upload http://stackoverflow.com/questions/5355846/iphone-facebook-video-upload I can't seem to get my video uploading working. My current code is NSString filePath NSBundle mainBundle pathForResource @ TestMovie ofType @ mp4 NSData data NSData dataWithContentsOfFile filePath NSMutableDictionary.. _upload.apiKey kApiKey _upload.appSecret kApiSecret NSString filePath NSBundle mainBundle pathForResource @ Test ofType @ mp4 NSURL fileURL NSURL fileURLWithPath filePath NSData data NSData..
Example or explanation of Core Data Migration with multiple passes? http://stackoverflow.com/questions/5995231/example-or-explanation-of-core-data-migration-with-multiple-passes nil for NSString mappingModelName in mappingModelNames NSURL fileURL NSBundle mainBundle URLForResource mappingModelName withExtension @ cdm NSMappingModel mappingModel NSMappingModel alloc..
Make movie file with picture Array and song file, using AVAsset http://stackoverflow.com/questions/6061092/make-movie-file-with-picture-array-and-song-file-using-avasset AVMediaTypeAudio outputSettings audioSettings retain NSURL fileURL NSBundle mainBundle URLForResource @ Big_Voice_1 withExtension @ caf NSLog @ @ fileURL AVAsset asset AVURLAsset URLAssetWithURL..
Using HTML and Local Images Within UIWebView http://stackoverflow.com/questions/747407/using-html-and-local-images-within-uiwebview Instead you have to load the HTML into the view with the correct baseURL NSString path NSBundle mainBundle bundlePath NSURL baseURL NSURL fileURLWithPath path webView loadHTMLString htmlString baseURL baseURL..
Play music in the background using AVAudioplayer http://stackoverflow.com/questions/7619794/play-music-in-the-background-using-avaudioplayer worked. Please help need to do it today. I had used following code NSString soundFilePath NSBundle mainBundle pathForResource @ Day At The Beach ofType @ mp3 NSURL fileURL NSURL alloc initFileURLWithPath soundFilePath.. view did load method like this void viewDidLoad NSURL url NSURL fileURLWithPath NSBundle mainBundle pathForResource @ in the storm ofType @ mp3 AVAudioPlayer audioPlayer AVAudioPlayer alloc initWithContentsOfURL..
Reducing piracy of iPhone applications http://stackoverflow.com/questions/846309/reducing-piracy-of-iphone-applications OS Application Signing The last one is easiest to check with this code NSBundle bundle NSBundle mainBundle NSDictionary info bundle infoDictionary if info objectForKey @ SignerIdentity nil do something Generally..
iPhone: How to load a View using a nib file created with Interface Builder http://stackoverflow.com/questions/863321/iphone-how-to-load-a-view-using-a-nib-file-created-with-interface-builder to the main view in the nib. 5 Now in MyViewController write the following line NSBundle mainBundle loadNibNamed @ myViewNib owner self options nil Now as soon as you do that calling your property self.myViewFromNib..
How to write data in plist? http://stackoverflow.com/questions/905542/how-to-write-data-in-plist The code is here NSString errorDesc nil NSPropertyListFormat format NSString plistPath NSBundle mainBundle pathForResource @ save ofType @ plist NSData plistXML NSFileManager defaultManager contentsAtPath plistPath.. NSString plistPath nil NSFileManager manager NSFileManager defaultManager if plistPath NSBundle mainBundle bundlePath stringByAppendingPathComponent @ Contents Info.plist if manager isWritableFileAtPath plistPath.. NSDictionary dictionaryWithObject NSDate date forKey NSFileModificationDate atPath NSBundle mainBundle bundlePath Update Nate Flink pointed out that some of the NSFileManager methods used above are deprecated...
Dispelling the UIImage imageNamed: FUD http://stackoverflow.com/questions/924740/dispelling-the-uiimage-imagenamed-fud a matter of style. UIImage imageFromMainBundleFile NSString aFileName NSString bundlePath NSBundle mainBundle bundlePath return UIImage imageWithContentsOfFile NSString stringWithFormat @ @ @ bundlePath aFileName..
Implementation of “Automatic Lightweight Migration” for Core Data (iPhone) http://stackoverflow.com/questions/2310216/implementation-of-automatic-lightweight-migration-for-core-data-iphone implementation to this replace YOURDB NSManagedObjectModel managedObjectModel if managedObjectModel nil return managedObjectModel NSString path NSBundle mainBundle pathForResource @ YOURDB ofType @ momd NSURL momURL NSURL fileURLWithPath path managedObjectModel NSManagedObjectModel alloc initWithContentsOfURL momURL return..
Difference between [UIImage imageNamed…] and [UIImage imageWithData…]? http://stackoverflow.com/questions/316236/difference-between-uiimage-imagenamed-and-uiimage-imagewithdata to load some images into my application from the file system. There's 2 easy ways to do this UIImage imageNamed fullFileName or NSString fileLocation NSBundle mainBundle pathForResource fileName ofType extension NSData imageData NSData dataWithContentsOfFile fileLocation UIImage imageWithData imageData I prefer the first one because..
Play sound on iPhone even in silent mode http://stackoverflow.com/questions/3740528/play-sound-on-iphone-even-in-silent-mode of one of your classes that plays the sounds you can instanciate sounds like this probably an instance variable AVAudioPlayer player NSString path NSBundle mainBundle pathForResource... NSURL url NSURL fileURLWithPath path player AVAudioPlayer alloc initWithContentsOfURL url When that's done you can play with it any time you..
Getting current device language in iOS? http://stackoverflow.com/questions/3910244/getting-current-device-language-in-ios
iOS SDK - Programmatically generate a PDF file http://stackoverflow.com/questions/4362734/ios-sdk-programmatically-generate-a-pdf-file 8.5 x 11 inches so this makes it easy to translate to from design time coordinates . In code I load the view UIView loadTemplate NSArray nib NSBundle mainBundle loadNibNamed @ ReportTemplate owner self options nil for id view in nib if view isKindOfClass UIView class return view return nil I then fill in various elements...
Getting a list of files in a directory with a glob http://stackoverflow.com/questions/499673/getting-a-list-of-files-in-a-directory-with-a-glob can't find a way to get a list of files with a glob for a given directory. I'm currently stuck with something along the lines of NSString bundleRoot NSBundle mainBundle bundlePath NSArray dirContents NSFileManager defaultManager directoryContentsAtPath bundleRoot ..and then stripping out the stuff I don't want which sucks. But.. c cocoa cocoa touch share improve this question You can achieve this pretty easily with the help of NSPredicate like so NSString bundleRoot NSBundle mainBundle bundlePath NSFileManager fm NSFileManager defaultManager NSArray dirContents fm contentsOfDirectoryAtPath bundleRoot error nil NSPredicate fltr NSPredicate predicateWithFormat.. '.jpg' NSArray onlyJPGs dirContents filteredArrayUsingPredicate fltr If you need to do it with NSURL instead it looks like this NSURL bundleRoot NSBundle mainBundle bundleURL NSArray dirContents fm contentsOfDirectoryAtURL bundleRoot includingPropertiesForKeys @ options NSDirectoryEnumerationSkipsHiddenFiles error nil NSPredicate..
iPhone Facebook Video Upload http://stackoverflow.com/questions/5355846/iphone-facebook-video-upload retain _facebook authorize _permissions delegate self However I can't seem to get my video uploading working. My current code is NSString filePath NSBundle mainBundle pathForResource @ TestMovie ofType @ mp4 NSData data NSData dataWithContentsOfFile filePath NSMutableDictionary params NSMutableDictionary dictionaryWithObjectsAndKeys.. has logged in void fbDidLogin _upload.accessToken _facebook.accessToken _upload.apiKey kApiKey _upload.appSecret kApiSecret NSString filePath NSBundle mainBundle pathForResource @ Test ofType @ mp4 NSURL fileURL NSURL fileURLWithPath filePath NSData data NSData dataWithContentsOfFile filePath NSMutableDictionary params NSMutableDictionary..
Example or explanation of Core Data Migration with multiple passes? http://stackoverflow.com/questions/5995231/example-or-explanation-of-core-data-migration-with-multiple-passes destinationStoreType NSSQLiteStoreType NSDictionary destinationStoreOptions nil for NSString mappingModelName in mappingModelNames NSURL fileURL NSBundle mainBundle URLForResource mappingModelName withExtension @ cdm NSMappingModel mappingModel NSMappingModel alloc initWithContentsOfURL fileURL BOOL ok migrationManager migrateStoreFromURL..
Make movie file with picture Array and song file, using AVAsset http://stackoverflow.com/questions/6061092/make-movie-file-with-picture-array-and-song-file-using-avasset audioWriterInput AVAssetWriterInput assetWriterInputWithMediaType AVMediaTypeAudio outputSettings audioSettings retain NSURL fileURL NSBundle mainBundle URLForResource @ Big_Voice_1 withExtension @ caf NSLog @ @ fileURL AVAsset asset AVURLAsset URLAssetWithURL fileURL options nil retain AVAssetReader audioReader..
Using HTML and Local Images Within UIWebView http://stackoverflow.com/questions/747407/using-html-and-local-images-within-uiwebview or file paths to refer to images does not work with UIWebView. Instead you have to load the HTML into the view with the correct baseURL NSString path NSBundle mainBundle bundlePath NSURL baseURL NSURL fileURLWithPath path webView loadHTMLString htmlString baseURL baseURL You can then refer to your images like this img src myimage.png..
Play music in the background using AVAudioplayer http://stackoverflow.com/questions/7619794/play-music-in-the-background-using-avaudioplayer I checked all stackoverflow links but none of them worked. Please help need to do it today. I had used following code NSString soundFilePath NSBundle mainBundle pathForResource @ Day At The Beach ofType @ mp3 NSURL fileURL NSURL alloc initFileURLWithPath soundFilePath NSError error playerTemp AVAudioPlayer alloc initWithContentsOfURL.. file of our application.. Update write this code in your controller's view did load method like this void viewDidLoad NSURL url NSURL fileURLWithPath NSBundle mainBundle pathForResource @ in the storm ofType @ mp3 AVAudioPlayer audioPlayer AVAudioPlayer alloc initWithContentsOfURL url error nil AVAudioSession sharedInstance setCategory..
Reducing piracy of iPhone applications http://stackoverflow.com/questions/846309/reducing-piracy-of-iphone-applications ASCII Add a key pair to Info.plist SignerIdentity Apple iPhone OS Application Signing The last one is easiest to check with this code NSBundle bundle NSBundle mainBundle NSDictionary info bundle infoDictionary if info objectForKey @ SignerIdentity nil do something Generally we don't have SignerIdentity in any of the App Store applications..
iPhone: How to load a View using a nib file created with Interface Builder http://stackoverflow.com/questions/863321/iphone-how-to-load-a-view-using-a-nib-file-created-with-interface-builder MyViewController 4 now connect your file's Owner outlet myViewFromNib to the main view in the nib. 5 Now in MyViewController write the following line NSBundle mainBundle loadNibNamed @ myViewNib owner self options nil Now as soon as you do that calling your property self.myViewFromNib will give you access to the view from your nib..
How to write data in plist? http://stackoverflow.com/questions/905542/how-to-write-data-in-plist to write the data but it get stored within my .app plist. The code is here NSString errorDesc nil NSPropertyListFormat format NSString plistPath NSBundle mainBundle pathForResource @ save ofType @ plist NSData plistXML NSFileManager defaultManager contentsAtPath plistPath NSMutableDictionary temp NSMutableDictionary NSPropertyListSerialization.. you really want to modify a bundled .plist here is some code NSString plistPath nil NSFileManager manager NSFileManager defaultManager if plistPath NSBundle mainBundle bundlePath stringByAppendingPathComponent @ Contents Info.plist if manager isWritableFileAtPath plistPath NSMutableDictionary infoDict NSMutableDictionary dictionaryWithContentsOfFile.. writeToFile plistPath atomically NO manager changeFileAttributes NSDictionary dictionaryWithObject NSDate date forKey NSFileModificationDate atPath NSBundle mainBundle bundlePath Update Nate Flink pointed out that some of the NSFileManager methods used above are deprecated. He posted an answer with the replacement methods below..
Dispelling the UIImage imageNamed: FUD http://stackoverflow.com/questions/924740/dispelling-the-uiimage-imagenamed-fud a semi colon at the end of a method definition is valid and a matter of style. UIImage imageFromMainBundleFile NSString aFileName NSString bundlePath NSBundle mainBundle bundlePath return UIImage imageWithContentsOfFile NSString stringWithFormat @ @ @ bundlePath aFileName Rincewind also included some example code to build your own..
Implementation of “Automatic Lightweight Migration” for Core Data (iPhone) http://stackoverflow.com/questions/2310216/implementation-of-automatic-lightweight-migration-for-core-data-iphone NSManagedObjectModel managedObjectModel if managedObjectModel nil return managedObjectModel NSString path NSBundle mainBundle pathForResource @ YOURDB ofType @ momd NSURL momURL NSURL fileURLWithPath path managedObjectModel NSManagedObjectModel alloc..
Difference between [UIImage imageNamed…] and [UIImage imageWithData…]? http://stackoverflow.com/questions/316236/difference-between-uiimage-imagenamed-and-uiimage-imagewithdata from the file system. There's 2 easy ways to do this UIImage imageNamed fullFileName or NSString fileLocation NSBundle mainBundle pathForResource fileName ofType extension NSData imageData NSData dataWithContentsOfFile fileLocation UIImage imageWithData..
Play sound on iPhone even in silent mode http://stackoverflow.com/questions/3740528/play-sound-on-iphone-even-in-silent-mode sounds you can instanciate sounds like this probably an instance variable AVAudioPlayer player NSString path NSBundle mainBundle pathForResource... NSURL url NSURL fileURLWithPath path player AVAudioPlayer alloc initWithContentsOfURL url When that's..
Getting current device language in iOS? http://stackoverflow.com/questions/3910244/getting-current-device-language-in-ios NS_AVAILABLE 10_5 2_0 note that this list does not indicate what language the app is actually running in the NSBundle mainBundle object determines that at launch and knows that information People interested in app language take a look at @mindvision's..
iOS SDK - Programmatically generate a PDF file http://stackoverflow.com/questions/4362734/ios-sdk-programmatically-generate-a-pdf-file easy to translate to from design time coordinates . In code I load the view UIView loadTemplate NSArray nib NSBundle mainBundle loadNibNamed @ ReportTemplate owner self options nil for id view in nib if view isKindOfClass UIView class return view..
Getting a list of files in a directory with a glob http://stackoverflow.com/questions/499673/getting-a-list-of-files-in-a-directory-with-a-glob with a glob for a given directory. I'm currently stuck with something along the lines of NSString bundleRoot NSBundle mainBundle bundlePath NSArray dirContents NSFileManager defaultManager directoryContentsAtPath bundleRoot ..and then stripping out.. this question You can achieve this pretty easily with the help of NSPredicate like so NSString bundleRoot NSBundle mainBundle bundlePath NSFileManager fm NSFileManager defaultManager NSArray dirContents fm contentsOfDirectoryAtPath bundleRoot error.. filteredArrayUsingPredicate fltr If you need to do it with NSURL instead it looks like this NSURL bundleRoot NSBundle mainBundle bundleURL NSArray dirContents fm contentsOfDirectoryAtURL bundleRoot includingPropertiesForKeys @ options NSDirectoryEnumerationSkipsHiddenFiles..
iPhone Facebook Video Upload http://stackoverflow.com/questions/5355846/iphone-facebook-video-upload delegate self However I can't seem to get my video uploading working. My current code is NSString filePath NSBundle mainBundle pathForResource @ TestMovie ofType @ mp4 NSData data NSData dataWithContentsOfFile filePath NSMutableDictionary params NSMutableDictionary.. _facebook.accessToken _upload.apiKey kApiKey _upload.appSecret kApiSecret NSString filePath NSBundle mainBundle pathForResource @ Test ofType @ mp4 NSURL fileURL NSURL fileURLWithPath filePath NSData data NSData dataWithContentsOfFile..
Example or explanation of Core Data Migration with multiple passes? http://stackoverflow.com/questions/5995231/example-or-explanation-of-core-data-migration-with-multiple-passes NSDictionary destinationStoreOptions nil for NSString mappingModelName in mappingModelNames NSURL fileURL NSBundle mainBundle URLForResource mappingModelName withExtension @ cdm NSMappingModel mappingModel NSMappingModel alloc initWithContentsOfURL..
Make movie file with picture Array and song file, using AVAsset http://stackoverflow.com/questions/6061092/make-movie-file-with-picture-array-and-song-file-using-avasset assetWriterInputWithMediaType AVMediaTypeAudio outputSettings audioSettings retain NSURL fileURL NSBundle mainBundle URLForResource @ Big_Voice_1 withExtension @ caf NSLog @ @ fileURL AVAsset asset AVURLAsset URLAssetWithURL fileURL options..
Using HTML and Local Images Within UIWebView http://stackoverflow.com/questions/747407/using-html-and-local-images-within-uiwebview work with UIWebView. Instead you have to load the HTML into the view with the correct baseURL NSString path NSBundle mainBundle bundlePath NSURL baseURL NSURL fileURLWithPath path webView loadHTMLString htmlString baseURL baseURL You can then refer..
Play music in the background using AVAudioplayer http://stackoverflow.com/questions/7619794/play-music-in-the-background-using-avaudioplayer but none of them worked. Please help need to do it today. I had used following code NSString soundFilePath NSBundle mainBundle pathForResource @ Day At The Beach ofType @ mp3 NSURL fileURL NSURL alloc initFileURLWithPath soundFilePath NSError error.. code in your controller's view did load method like this void viewDidLoad NSURL url NSURL fileURLWithPath NSBundle mainBundle pathForResource @ in the storm ofType @ mp3 AVAudioPlayer audioPlayer AVAudioPlayer alloc initWithContentsOfURL url error..
Reducing piracy of iPhone applications http://stackoverflow.com/questions/846309/reducing-piracy-of-iphone-applications Apple iPhone OS Application Signing The last one is easiest to check with this code NSBundle bundle NSBundle mainBundle NSDictionary info bundle infoDictionary if info objectForKey @ SignerIdentity nil do something Generally we don't have SignerIdentity..
iPhone: How to load a View using a nib file created with Interface Builder http://stackoverflow.com/questions/863321/iphone-how-to-load-a-view-using-a-nib-file-created-with-interface-builder Owner outlet myViewFromNib to the main view in the nib. 5 Now in MyViewController write the following line NSBundle mainBundle loadNibNamed @ myViewNib owner self options nil Now as soon as you do that calling your property self.myViewFromNib will..
How to write data in plist? http://stackoverflow.com/questions/905542/how-to-write-data-in-plist within my .app plist. The code is here NSString errorDesc nil NSPropertyListFormat format NSString plistPath NSBundle mainBundle pathForResource @ save ofType @ plist NSData plistXML NSFileManager defaultManager contentsAtPath plistPath NSMutableDictionary.. here is some code NSString plistPath nil NSFileManager manager NSFileManager defaultManager if plistPath NSBundle mainBundle bundlePath stringByAppendingPathComponent @ Contents Info.plist if manager isWritableFileAtPath plistPath NSMutableDictionary.. changeFileAttributes NSDictionary dictionaryWithObject NSDate date forKey NSFileModificationDate atPath NSBundle mainBundle bundlePath Update Nate Flink pointed out that some of the NSFileManager methods used above are deprecated. He posted an..
Dispelling the UIImage imageNamed: FUD http://stackoverflow.com/questions/924740/dispelling-the-uiimage-imagenamed-fud is valid and a matter of style. UIImage imageFromMainBundleFile NSString aFileName NSString bundlePath NSBundle mainBundle bundlePath return UIImage imageWithContentsOfFile NSString stringWithFormat @ @ @ bundlePath aFileName Rincewind also included..
|