Hide resources in iOS framework - xcode

I am developing Universal iOS framework using this guide.
How to hide images inside framework from other developers?
Also, I am not sure, do we need Info.plist file inside framework?

I solve my problem by encrypt the resources. I am not sure, that is the best way to resolve, but it works in my case.
Here is a simple OS X app that encrypt files before adding it to the framework.
Code for decrypt:
NSError* error;
NSData* encryptedData = [NSData dataWithContentsOfFile:filePath];
NSData* decryptedData = [RNDecryptor decryptData:encryptedData
withPassword:#"SAMPLE-KEY"
error:&error];
UIImage* image = [UIImage imageWithData:decryptedData];
`
Code for encrypt:
NSData* data = [NSData dataWithContentsOfFile:filePath];
NSError* error;
NSData* encryptedData = [RNEncryptor encryptData:data
withSettings:kRNCryptorAES256Settings
password:#"SAMPLE-KEY"
error:&error];
[encryptedData writeToFile:encryptedFilePath atomically:YES];

Related

Copy files 10.10 Yosemite

I have project with MAgicalRecords and OSX it is convertor SQLITe -> coreData .
Before Yosemite - it worked well but after update - have some troubles
My Steps
[MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
//do some workd with save entity }];
than i try to copy database which i get after converting
if ([fileManager fileExistsAtPath:from]) {
NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:from];
[fileHandle seekToEndOfFile];
[fileHandle closeFile];
[fileManager copyItemAtPath:from toPath:to error:NULL];
}
BUT file here HAS a tables and colums before copy and his size is 165kb - and after coping NO - he is empty. Does it new feature of MAC ?
As you can see - i put [fileHandle closeFile]; but it still not working.
I noticed that if i close project before copyng file "from" has 1.8mb and has all data.
and there are 3 files
Main.sqlite
Main.sqlite-shm
Main.sqlite-wal
It looks like OS white data in "some memory" but not in file directly.
I try to find solutions but didn find any. Please help
Copying these three files will not fully copy your database. I suggest the answer from this question:
Using MagicalRecord to prepopulate a database (swift). -wal journal created, however, data not copied to database
Thanks it was problem with SQL journal mode
+ (NSDictionary *) getOptionsForCreate {
NSDictionary *pragmaOptions = [NSDictionary dictionaryWithObject:#"MEMORY" forKey:#"journal_mode"];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
pragmaOptions, NSSQLitePragmasOption, nil];
return options;
}
NSPersistentStore *store = [self addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:url
options:[sel getOptionsForCreate]
error:&error];

Writing/reading to paths with interleaved double dots fails on iOS 8

This code fails on iOS 8, although it would work on iOS 7
UIImage *imageTest = ...
NSString *file = #"../Documents/Test.png";
NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent: file];
[UIImagePNGRepresentation(imageTest) writeToFile: fullpath atomically: YES];
UIImage *image = [UIImage imageNamed: file];
On iOS 8 I need to use this instead
NSString *file = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:#"Test.png"];
[UIImagePNGRepresentation(imageTest) writeToFile:file atomically:YES];
UIImage *image = [[UIImage alloc] initWithContentsOfFile: file];
...but then I have to refactor my project and a third party library that works with paths relative to the main bundle.
It seems to me that paths like "/PathToMainBundle/MyApp.app/../Documents/something" are either not properly resolved, or not allowed at all by iOS 8
That path should be the same as "/PathToMainBundle/Documents/something"
In iOS8, Resource Directory(App.app), Data Directory(NSCachesDirectory, NSTemporaryDirectory,..) are managed separately as below.
iOS7 Directory Hierarchy
App UUID
Documents
Library
Caches
Preferences
tmp
App.app
iOS8 Directory Hierarchy
Resource Directory UUID
App.app
Data Directory UUID
Documents
Library
Caches
Preferences
tmp
So, you should fix code based on absolute path in iOS8.
UIImage *imageTest = ...
NSString *fullpath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:#"Test.png"];
[UIImagePNGRepresentation(imageTest) writeToFile: fullpath atomically: YES];
UIImage *image = [UIImage imageNamed: fullpath];

UIImage imageWithContentsOfFile: not working on iOS8

When I test my app on iOS8 beta3 and beta5, I found an bug that about [UIImage imageWithContentsOfFile:].
When image resources are stored in sub-bundle of a main bundle, it will return nil if we initialize UIImage via the following method:
NSString *testBundlePath = [[NSBundle mainBundle] pathForResource:#"test" ofType:#"bundleā€¯];
NSBundle *bundle = [NSBundle bundleWithPath:testBundlePath];
NSString *path = [bundle pathForResource:#"play.png" ofType:nil];
UIImage *image = [UIImage imageWithContentsOfFile:path]; //iOS8 image = nil, iOS7 image != nil
But when the image resources are stored in main bundle, UIImage Initialization can be succeed through the following method:
NSString *path = [[NSBundle mainBundle] pathForResource:#"play.png" ofType:nil];
UIImage *image = [UIImage imageWithContentsOfFile:path]; //iOS8 and iOS7 image != nil
We have found this problem under iOS8 beta3 and it still exists under iOS8 beta 5.
The Demo app directory structure was below:
XXX.app
|----test~ipad.bundle
|----play.png
|----test~iphone.bundle
|----play.png
|----play.png
|----play~iphone.png
|----play~ipad.png
......
Does anyone have the same problem? I think this is a bug on iOS8, Therefore, many apps have used bundle to organize resources, such as images. But now, this bug will make thousands of apps become ugly and hard to use. We really hope that Apple can fix this bug in the next version, otherwise, all of my app will have to developing an new version for this bug!
It's not actually broken, you're just sending it the wrong path.
I'm guessing that you are using the simulator, and have saved a file somewhere in your app and then made note of the full path to that file. However, when you rebuild your app the UUID for the installed app changes, and your saved path is no longer valid (even though the files are still there). You can see your current active path by checking [[NSFileManager defaultManager] currentDirectoryPath] Note that the value changes each time you rebuild and re-deploy your app.
To get to your actual file, you'll need to do something like this:
NSString *image = #"myImage.png";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cache = [paths objectAtIndex:0];
NSString *fullPath = [NSString stringWithFormat:#"%#/%#", cache, image];
UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
pathForResource:ofType: only looks in the Resources folder (and localised folders). If you are placing files into dedicated folders in the bundle then you need to use pathForResource:ofType:inDirectory: and supply the directory name.
Apple has fixed this bug on iOS8.1,Cheers
just use
NSString *fullPath = [bundle pathForResource:name ofType:#"png"];
NSData *data = [NSData dataWithContentsOfFile:fullPath];
UIImage *image = [UIImage imageWithData:data];

Cannot open PDF file using UIWebView in iOS8beta5

I have working project in which i display pdf file in UIWebView
While testing my application in iOS8beta5 with XCode5, it did not work
In log it display failed to find PDF header : '%PDF' not found
I create sample application with below code which also have same problem
CODE :
self.myWebView.delegate = self;
NSString *path = [[NSBundle mainBundle] pathForResource:#"201" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[self.myWebView loadRequest:request];
I read release note, Apple wrote that
Quicklook framework may did not display PDF file in some application
but they did not mention any thing about UIWebView,
Reference
NOTE :
This problem was not came in iOS8beta4.
Same problem is also occur in XCode6 + iOS8beta5.
I also check with different PDF files but have same problem.
QUESTION :
1] Is there any one had done fix for the above problem ?
If yes, please provide me some sample code.
I found a workaround for viewing the PDF in WebView
// Create pdf path & url
NSString *path = [[NSBundle mainBundle] pathForResource:#"201" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
// Load pdf in WebView
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:targetURL];
[self.webView loadData:pdfData MIMEType:#"application/pdf" textEncodingName:#"utf-8" baseURL:nil];

What format is person's ImageData(CFDataRef) in AddressBook?(Jpeg or PNG)?Or how to determine?

From AddressBook's API ABPersonCopyImageData I can get a CFDateRef which is toll-free bridge to NSData. And I want to write this data to file, but what file extension should I use ?
.jpeg or .png?
The documentation doesn't mention what the data is.Is there any way to know?
NSData *imgData = (__bridge NSData *)ABPersonCopyImageData(person);
UIImage *img = [UIImage imageWithData:imgData];
if (!img) {
img = [UIImage imageNamed:#"noImage.png"];
}

Resources