I've an odd behavior with p12 certificates and amazon iot.
If i include a p12 file in the project ide, and connect to aws iot, every thing works fine
NSBundle *bundle = [NSBundle mainBundle];
NSString *resource = [bundle pathForResource:nil ofType:#"p12"];
certificate = [NSData dataWithContentsOfFile:resource];
[self continueConnect:certificate];
but if i download the certificate from the server and save into a local file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingString:#"/certificate.p12"];
certificate = [NSData dataWithContentsOfFile:appFile];
[self continueConnect:certificate];
I get the following error: CFNetwork SSLHandshake failed (-9829)
I've checked in a for loop that both certificates are indentical
any tip?
Related
In my app, I am using Plists for making different lists. I want each Plist to be one list, and to be able to view all available lists in a TableView. To create the Plist I am using this:
NSString *plistname = [alertController.textFields[0].text stringByAppendingString:#".plist"];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pathFirstTime = [documentsDirectory stringByAppendingPathComponent:plistname];
[#{} writeToFile: pathFirstTime atomically: YES];
I went in to finder after getting the path, and verified the Plist file IS there.
I then am creating an NSArray of all the Plist in documents directory to be able to load into a TableView using this code, but it returns an empty array:
NSBundle *bundle = [NSBundle mainBundle];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
self.files = [bundle pathsForResourcesOfType:#"plist" inDirectory:documentsDirectory];
NSLog(#"%#", self.files);
I have an iPhone app where I have to modify the plist at runtime. I am successfully able to do it on simulator but when I run it on device it retrieves the data from the old plist and modification is not done. This is the code I am using for getting the path of the plist -
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:#"Customer.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path])
{
path = [[NSBundle mainBundle] pathForResource:#"Customer" ofType:#"plist"];
}
NSMutableDictionary *mainDictionary;
mainDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
To write a dictionary on plist file this line may work
[dicionaryToWrite writeToFile:path atomically: TRUE];
I can do the reverse with the following: But cannot copy to the app bundle.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
// Destination path
NSString *fileInDocumentsPath = [documentsPath stringByAppendingPathComponent:#"Passwords File.txt"];
// Origin path - used when file is in bundle
NSString *fileInBundlePath = [[NSBundle mainBundle] pathForResource:#"Passwords File" ofType:#"txt"];
// File manager for copying File in Bundle to Sandbox
NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager copyItemAtPath:fileInBundlePath toPath:fileInDocumentsPath error:&error];
The application bundle is read only. It cannot be modified after you deploy the app.
Files in your app's documents folder can be accessed via iTunes if the app supports File Sharing. Check out How to enable File Sharing for my app.
I am making an app that can dowload from FTP server that protected with username and password file and saved it in documentsDirectory. I have managed to download file directly from HTTP, save and dispaly it. Now I wish to do so from FTP. Here is my code:
-(IBAction)download:(id)sender
{
NSString *stringURL = #"http://www.image.png";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/%#", documentsDirectory,#"filename3.png"];
[urlData writeToFile:filePath atomically:YES];
}
}
-(IBAction)viewImage:(id)sender
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:#"filename3.png"];
UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
[imageV setImage:img];
}
Can anyone please point me to CFNetwork example. I need to connect to ftp server, list files in folder and download them. Already looked at http://developer.apple.com/library/ios/#Documentation/Networking/Conceptual/CFNetwork/CFFTPTasks/CFFTPTasks.html#//apple_ref/doc/uid/TP30001132-CH9-SW1 but it`s not so clear.
Consider using BlackRaccoon to work with FTP.
Is it possible to write new file to bundle resource directory in iOS app?
No there is no way to write in the bundle dir.. because the bundle dir is code signed with SSL certificate and you can't break it. however you can easily write in the documents directory of you iphone application
You can get the documents directory path using this -
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
return [paths objectAtIndex:0];
Or you can copy the resources needed and then operate on files with writing permission.
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = dirPaths[0];
NSString *databasePath = [documentsDir stringByAppendingString:#"/TwigitDatabase.db"];
NSFileManager *fm = [NSFileManager defaultManager];
if(![fm fileExistsAtPath:databasePath]) { // Checking whether the my database was copied earlier, though it could be saved in some preferences property.
NSError *error;
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"TwigitDatabase" ofType:#"db"];
[[NSFileManager defaultManager] copyItemAtPath:soundFilePath toPath:databasePath error:&error];
NSLog(#"%#", error);
}