In my app I'm doing various request on server API. When I'm doing those requests, part of my requester class is:
NSString *authString = [[[NSString stringWithFormat:#"serverUsername:serverPass"]dataUsingEncoding:NSUTF8StringEncoding] base64EncodedString];
NSString *verifString = [NSString stringWithFormat:#"Basic %#",authString];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
NSData *myRequestData = [NSData dataWithBytes:[ms UTF8String] length:[ms length]];
[request setHTTPBody:myRequestData];
I'm not including all of source code, but then I have another strings, that I don't want to be visible in source code (fingerprints etc).
I was searching for code obfuscating, but to no success. Is there any way, to prevent my credential strings to be visible in x-code?
I think the best way is to store it in a plist file.
- (NSString *)saveRecommendUserData {
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:#"Userdata.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:path])
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:#"Userdata" ofType:#"plist"];
[fileManager copyItemAtPath:bundle toPath: path error:&error];
}
return path;
}
Related
I'm trying to determine the file size on disk of a PHAsset video.
The following code is returning am error "The file “IMG_0188.mov” couldn’t be opened because you don’t have permission to view it."
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
options.version = PHVideoRequestOptionsVersionOriginal;
[[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset *avAsset, AVAudioMix *audioMix, NSDictionary *info) {
videoURL = [(AVURLAsset*)avAsset URL];
NSNumber *videoDiskFileSize;
NSError *error;
[videoURL getResourceValue:&videoDiskFileSize forKey:NSURLFileSizeKey error:&error];
if(error){
NSLog(#"ERROR %#", error.localizedDescription);
}
NSLog(#"size is %f",[videoDiskFileSize floatValue]/(1024.0*1024.0));
}];
Here's the correct way to do it.
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
options.version = PHVideoRequestOptionsVersionOriginal;
[[PHImageManager defaultManager] requestExportSessionForVideo:asset options:options exportPreset:AVAssetExportPresetHighestQuality resultHandler:^(AVAssetExportSession *exportSession, NSDictionary *info) {
CMTime videoDuration = CMTimeMultiplyByFloat64(exportSession.asset.duration, 1);
exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, videoDuration);
NSLog(#"Byyte size = %lld", exportSession.estimatedOutputFileLength);
videoSize = exportSession.estimatedOutputFileLength;
}];
Can we send NSString Value between devices connected via Bluetooth, using Game Center?
Here is some part of my code:
typedef enum {
messageType1 = 0;
messageType2 = 1;
}
messageType;
typedef struct {
MessageType messageType;
NSString *myName;
} MyMessage;
And In my Class I have this method to send the message:
MyMessage myMessage;
myMessage.messageType = messageType2;
myMessage.myName = #"ABCDEFGH";
NSData *data = [NSData dataWithBytes:&myMessage length:sizeof(MyMessage)];
[self sendDataToAllPeers:data withDataMode:GKSendDataReliable error:error];
to receive data I have method:
-(void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context{
MyMessage myMessage = *((MyMessage *) [data bytes]);
type = myMessage.messageType;
name = myMessage.myName;
}
Question: How can I get myName ? (I am able to get MessageType)
Send NSData as Archived NSArray:
NSArray *array = [[NSArray alloc] initWithObjects:myMessage.messageType, myMessage.myName, nil];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:array];
[self sendDataToAllPeers:data];
Receive NSData and Unarchive to NSArray:
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData: data];
type = [array objectAtIndex:0];
name = [array objectAtIndex:1];
`Okay so I am trying to pull questions and possible answers from a plist file I have created
<key>Question1</key>
<string></string>
<key>Answer1</key>
<array/>
<key>4</key>
<string>A</string>
<key>2</key>
<string>B</string>
<key>3</key>
<string>C</string>
So I have tried to do this in code from looking a various tutorials, I am only new to this so I know I have it all wrong
so then I want to place the question in an label created in the storyboard and the same with the possible answers????
`
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *listPath = [[self docDir]stringByAppendingPathComponent:#"work.plist"];
if (![[NSFileManager defaultManager]fileExistsAtPath:listPath]) {
[[NSFileManager defaultManager] copyItemAtPath:[[NSBundle mainBundle]pathForResource:#"work" ofType:#"plist"]toPath:listPath error:nil];
}
NSMutableArray *array = [NSMutableArray arrayWithContentsOfFile:listPath];NSLog(#"count: %i", [array count]);
NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
propertyListFromData:#"work.plist";
self.firstQuestion = [temp objectForKey:#"Question1"];
self.firstanswer = [NSMutableArray arrayWithArray:[temp objectForKey:#"Answer"]];`
TRY this too.
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [path objectAtIndex:0];
NSString *plistpath = [documentsPath stringByAppendingPathComponent:#"question.plist"];
NSMutableArray *savedStock = [[NSMutableArray alloc] initWithContentsOfFile:plistFilePath];
for (int i=0; i<[savedStock count]; i++)
{
[A-array addObject:[[savedStock objectAtIndex:i] valueForKey:#"A"]];
[B-array addObject:[[savedStock objectAtIndex:i] valueForKey:#"B"]];
}
I'm not able to copy this sqlite file in documents directory: nothing has been copied.... please anyone knows what I'm I missing? Thank you!
BOOL success;
//documents path
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *dbPath = [documentsDir stringByAppendingPathComponent:#"verbi2.sqlite"];
NSFileManager *fileManager=[NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:dbPath];
if (success) return;
//bundle path
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"verbi2.sqlite"];
[fileManager copyItemAtPath:databasePathFromApp toPath:dbPath error:nil];
I've solved creating a new .sqlite file (verbi5.sqlite); probably something was corrupted.
All,In my requirement need to send a mail with attached text file, which is in document directory,Here i can get the path of file which is in document directory,How do i attach the file from my ipad to send.
here is the code which i have tried
MFMailComposeViewController *picker=[[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate=self;
if ([MFMailComposeViewController canSendMail]){
// Create and show composer
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSLog(#"directry path %#",paths);
NSString *fullPath = [[paths lastObject] stringByAppendingPathComponent:#"Logs/log-858743.txt"];
NSLog(#"directry full path %#",fullPath);
NSData *data = [NSData dataWithContentsOfFile: fullPath];
NSLog(#"Data value %#",data);
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:fullPath];
if (fileExists) {
NSLog(#"file is there");
}else{
NSLog(#"file is not there");
}
[picker setSubject:#"Backup"];
[picker addAttachmentData:data mimeType:#"text/rtf" fileName:#"log.txt"];
[picker setMessageBody:#"testing." isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release]; }
else{
// Show some error message here
}
Here a sample, try this
MFMailComposeViewController *mViewController = [[MFMailComposeViewController alloc] init];
mViewController.mailComposeDelegate = self;
//Imposto l'oggetto
[mViewController setSubject:#"Invio Copia Commissione"];
//Preparo l' A: Devo spezzare gli indirizzi E-mail
NSArray *toRecipients = [NSArray arrayWithArray:[Globals.AEmail componentsSeparatedByString:#";"]];
[mViewController setToRecipients:toRecipients];
//Preparo il Cc: Devo spezzare gli indirizzi E-mail
if ([Config.EmailAgg length] != 0) {
NSArray *CcRecipients = [NSArray arrayWithArray:[Config.EmailAgg componentsSeparatedByString:#";"]];
[mViewController setCcRecipients:CcRecipients];
}
//Setto il corpo dell'E-mail
[mViewController setMessageBody:Globals.TestoEmail isHTML:NO];
//A questo punto visto che ho fatto 30 salvo il testo anche come file allegato dell'E-mail
[Globals.TestoEmail writeToFile:[NSString stringWithFormat:#"%#/CopiaCommissione.txt", Globals.DocumentsPath] atomically:TRUE encoding:NSUTF8StringEncoding error:nil];
NSData *Allegato = [NSData dataWithContentsOfFile:[NSString stringWithFormat:#"%#/CopiaCommissione.txt", Globals.DocumentsPath]];
[mViewController addAttachmentData:Allegato mimeType:#"text/plain" fileName:#"CopiaCommissione.txt"];
[self presentModalViewController:mViewController animated:YES];
[mViewController release];
try to change mimeType in your code like this
[picker addAttachmentData:data mimeType:#"text/plain" fileName:#"log.txt"];