I want to this string to nsdate
"2012-12-25T18:58:57.649Z"
I Know how to convert nsstring to nsdate but i am unable to find the proper format. I set following format but it does not work. Please suggest
[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehaviorDefault];
[dateFormatter setDateFormat:#"yyyy-MM-ddTHH:mm:ss"];
Hope this help
- (NSDate *)dateFromISO8601:(NSString *)str{
if(![str isKindOfClass:NSString.class]){
return nil;
}
static NSDateFormatter* sISO8601 = nil;
if (!sISO8601) {
sISO8601 = [[NSDateFormatter alloc] init];
[sISO8601 setTimeStyle:NSDateFormatterFullStyle];
[sISO8601 setDateFormat:#"yyyy-MM-dd'T'HH:mm:ss.S"];
[sISO8601 setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
}
if ([str hasSuffix:#"Z"]) {
str = [str substringToIndex:(str.length-1)];
}
NSDate *d = [sISO8601 dateFromString:str];
return d;
}
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;
}];
What I am trying to do is this.
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url2 = [[NSBundle mainBundle] URLForResource:#"NAN" withExtension:#"mov"];
GPUImageMovie *movie2 = [[GPUImageMovie alloc] initWithURL:url2];
movie2.playAtActualSpeed = YES;
filter0 = [[GPUImageSepiaFilter alloc] init];
[movie2 addTarget:filter0];
[filter0 addTarget:view0]; // view0 is a GPUImageView taken in nib
[self recordVideo];
isRecording = YES;
[movie2 startProcessing];
[movieWriter setCompletionBlock:^{
if (isRecording) {
[self stopRecording];
isRecording = NO;
} }];
}
-(void)recordVideo {
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:#"file.mov"];
NSURL *url = [NSURL fileURLWithPath:path];
NSFileManager *fm = [NSFileManager defaultManager];
[fm removeItemAtPath:path error:nil];
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:url size:CGSizeMake(640, 480)];
[filter0 addTarget:movieWriter];
[movieWriter startRecording];
}
-(void)stopRecording {
[movieWriter finishRecording];
}
But this is not working at all. I always get a black video with this code. There is no crash, I get a black video with the same duration as of original video. Has anyone faced the same issue. Kindly help.
Any help would be great.
`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"]];
}
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"];
here is code for my database
SQLiteTutorialAppDelegate.m
$.-(void) readAnimalsFromDatabase {
sqlite3 *database;
animals = [[NSMutableArray alloc] init];
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "select * from animals";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSString *aImageUrl = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
// Create a new animal object with the data from the database
Animal *animal = [[Animal alloc] initWithName:aName description:aDescription url:aImageUrl];
// Add the animal object to the animals Array
[animals addObject:animal];
[animal release];
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
and here RootViewController.m
$.- (void)searchBar:(UISearchBar *)SearchBar textDidChange:(NSString *)searchText {
[copyListOfItems removeAllObjects];
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
SQLiteTutorialAppDelegate *appDelegate = (SQLiteTutorialAppDelegate *)[[UIApplication sharedApplication] delegate];
for (NSArray *rowArray in appDelegate.animals)
{
for ( NSString *aName in rowArray )
{
[searchArray addObject:rowArray]; // HERE CRASH
}
}
for (NSString *sTemp in searchArray)
{
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length == 0)
[copyListOfItems addObject:sTemp];
}
[self.tableView reloadData];
}
please help me how to make search bar search database in TableView
http://www.appcoda.com/search-bar-tutorial-ios7/
This gives you an example of how the search bar uses things around it and how it works
I Recently worked on something similar and this website should tell you everything wrong as well as give you an example of how it works