Convert yyyy-MM-ddTHH:mm:ss.SSSZ format to default timezone

- (NSDate *) localDateStringForISODateTimeString:(NSString *) anISOString

{
NSDateFormatter *isoDateFormatter = [[NSDateFormatter alloc] init];
[isoDateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
[isoDateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];

NSDateFormatter *userFormatter = [[NSDateFormatter alloc] init];
[userFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];

NSDate *date = [isoDateFormatter dateFromString:anISOString];
return [dateFormatter dateFromString:[userFormatter stringFromDate:date]];
}

iOS orientation animation does not happen smoothly

If you apply any changes to the layer of underlying view.

for example,

shadowImageView.layer.masksToBounds = NO;
shadowImageView.layer.shadowOffset = CGSizeMake(-5, 0);
shadowImageView.layer.shadowOpacity = 1.0;

iOS custom UDID

UIImagePickerController is shifted by ~20px

Subclass UIImagePickerController and override

- (BOOL)  shouldAutorotate
{
return NO;
}

CoreData: error: (19) PRIMARY KEY must be unique

Set the Z_MAX to largest Z_PK value in the corresponding table.

UPDATE "main"."Z_PRIMARYKEY" SET "Z_MAX" = n where "Z_ENT" = n

Cited from: why is this code raising the coredata error 19 primary key must be unique

Add image to custom photo album

- (void) addAssetWithURL:(NSURL *) assetURL toPhotoAlbum:(NSString *) album
{
__block ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

[library assetForURL:assetURL
resultBlock:^(ALAsset *asset)
{
NSString *groupName = [[NSUserDefaults standardUserDefaults] objectForKey:@”groupURL”];
NSURL *groupURL = [[NSURL alloc] initWithString:groupName?groupName:@””];

[library groupForURL:groupURL
resultBlock:^(ALAssetsGroup *group)
{
NSString *groupName = [group valueForProperty:ALAssetsGroupPropertyName];

if ([album isEqualToString:groupName])
{
[group addAsset:asset];
}
else
{
__weak ALAssetsLibrary *lib = library;

[library addAssetsGroupAlbumWithName:album resultBlock:^(ALAssetsGroup *group)
{
NSString *groupName = [group valueForProperty:ALAssetsGroupPropertyName];
NSURL *groupURL = [group valueForProperty:ALAssetsGroupPropertyURL];
[[NSUserDefaults standardUserDefaults] setObject:groupURL.absoluteString forKey:@”groupURL”];

[lib enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
if ([album isEqualToString:groupName])
{
[group addAsset:asset];
}

} failureBlock:^(NSError *error)
{
}];

} failureBlock:^(NSError *error)
{
}];
}

} failureBlock:^(NSError *error)
{
}];

} failureBlock:^(NSError *error)
{
}];
}

- (void) addToPhotoAlbum:(NSString *) album sourceType:(UIImagePickerControllerSourceType) sourceType assetURL:(NSURL *) assetURL
{
if (sourceType == UIImagePickerControllerSourceTypePhotoLibrary)
{
[self addAssetWithURL:assetURL toPhotoAlbum:kAlbumName];
}
else
{
__block ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

[library writeImageToSavedPhotosAlbum:self.CGImage
orientation:(ALAssetOrientation)self.imageOrientation
completionBlock:^(NSURL *assetURL, NSError *error)
{
[self addAssetWithURL:assetURL toPhotoAlbum:album];
}];
}
}

2012 in review

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here’s an excerpt:

4,329 films were submitted to the 2012 Cannes Film Festival. This blog had 25,000 views in 2012. If each view were a film, this blog would power 6 Film Festivals

Click here to see the complete report.

Follow

Get every new post delivered to your Inbox.

Join 335 other followers