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];
}];
}
}

Advertisements

App Store upload failure – armv6

XCode 4.5 and above won’t support armv6 architecture.

XCode 4.2 – You can create build that supports armv6 architecture, but you have to do the steps mentioned in the following forum.

http://stackoverflow.com/questions/4198676/warning-iphone-apps-should-include-an-armv6-architecture-even-with-build-config

iPhone 5 won’t support armv6 and has new architecture armv7s.

Apple server also has some issue some times https://discussions.apple.com/thread/3822193?start=0&tstart=0

ARC: respondsToSelector Issue

Do either of the following.

[(NSObject*)self.delegate respondsToSelector:@selector(myClass:willDoSomething:)]

Or

@property (nonatomic, weak) NSObject<MyClassDelegate>* delegate;

Or

@protocol MyClassDelegate <NSObject>

Cited from http://stackoverflow.com/questions/9579337/self-delegate-respondstoselector-does-not-compile

IOS Coding Tips

1. Create view objects in Interface builder not in source code.

2. Flower brackets always be there in if conditions or while loops, even it has single statement.

3. Give one line space between @implementation and @synthesize

4. Open flower bracket “{” should start in next line.

5. Give one line space above conditional or loop statements like if, while, for.

6. The method name itself should resembles its behavior.

7. Remove unnecessary methods which are created by the file templates.

8. Use Edit->Format->Re-Indent to re-indent the selection of statements.

9. Don’t use string literals as keys, make the string literal as constant and use that. Place all constants in a common file.

10. Try to use property directly than calling the accessory method. for example Object.memberVariable than [Object memberVariable];

11. Try to define all literals in common file.

12. Instead of using literals, create meaningful constants for them in common file and use them.

13. Always group the things like constants, statements, etc.

14. The format for method signature should be like
        – (void) methodName:(id) sender;

15. One line space between logical group of statements and two lines between physical groups.

16. Try to eliminate autorelease objects, instead use retain and release.

17. If you are declaring a UI object, please suffix the type to the variable. For example, if you are declaring a UILabel object with name ‘userName’, then name it ‘userNameLabel’.

18. Maintain all image names in lowercase with underscore dividing the inline words.

19. Directly access the variable instead of using property in the same class. For example, don’t access

UITableView mTableView;
@Property () UITableView *tableView;
//To reload the table in the same class use
[mTableView reloadData]; // correct
[self.tableView reloadData]; //wrong

UIImageView rounded corners with border

If you are using a UIImageView to display the image you can simply do the following:

imageView.layer.cornerRadius = 5.0;
imageView.layer.masksToBounds = YES;

And to add a border:

imageView.layer.borderColor = [UIColor lightGrayColor].CGColor;
imageView.layer.borderWidth = 1.0;

I believe that you’ll have to import <QuartzCore/QuartzCore.h> and link against it for the above code to work.

Cited from: http://stackoverflow.com/questions/262156/uiimage-rounded-corners

Blogged with the Flock Browser

XCode 4: Wireless iPhone/iPad app distribution (OTA)

XCode 4 seems to be doing something different from XCode 3.x.

Do the following steps

Add Entitlements file and set the key value pair for get-task-allow (Can be debugged) to NO.

Go to Target build settings, under the Code Signing Entitlements section, add the Entitlements.plist under the “Release” setting and ensure that your Ad Hoc Provisioning profile is selected for “Release” under Code Signing Identity.

Create .ipa and .plist files

  1. Edit scheme and select destination to device.
  2. Archive the project (Product -> Archive).
  3. Go to Archives section in Organizer window.
  4. Select the archived distribution file
  5. Click on share… button
  6. Point the identity dropdown to respective Ad Hoc Provisioning profile
  7. Click Next
  8. Select the check box (Save for Enterprise Distribution)
  9. Fillup the fields (Application URL should point to the .ipa file (complete url))
  10. Click on save button (It will create .ipa (app) and .plist (manifest) files)


Create an index.html file similar to the following

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
        “http://www.w3.org/TR/html4/loose.dtd”&gt;
<html>
<head>
<title>My Cool app</title>
</head>
<body>
<ul>
    <li><a href=”http://mycoolapp/build/distribution.mobileprovision”&gt;
                Install Example Provisioning File</a></li>
    <li><a href=”itms-services://?action=download-manifest&url=http://mycoolapp/build/app.plist”>
                Install Example Application</a></li>
</ul>
</body>
</html>

Check whether the app.plist contain the full url that points to the .ipa file

Place the files in the server (http://mycoolapp/build/)

Launch the browser in the device and point to http://mycoolapp/build/index.html
Download the provisioning profile and the application.

Reference:

http://jeffreysambells.com/posts/2010/06/22/ios-wireless-app-distribution/

http://www.paradeofrain.com/2010/11/taking-the-pain-out-of-ad-hoc-testing/

Blogged with the Flock Browser

XCode 4: Wireless iPhone/iPad app distribution

XCode 4 seems to be doing something different from XCode 3.x.

Do the following steps

Add Entitlements file and set the key value pair for get-task-allow (Can be debugged) to NO.

Go to Target build settings, under the Code Signing Entitlements section, add the Entitlements.plist under the “Release” setting and ensure that your Ad Hoc Provisioning profile is selected for “Release” under Code Signing Identity.

Create .ipa and .plist files

  1. Archive the project (Product -> Archive).
  2. Go to Archives section in Organizer window.
  3. Select the archived distribution file
  4. Click on share… button
  5. Point the identity dropdown to respective Ad Hoc Provisioning profile
  6. Click Next
  7. Select the check box (Save for Enterprise Distribution)
  8. Fillup the fields (Application URL should point to the .ipa file (complete url))
  9. Click on save button (It will create .ipa (app) and .plist (manifest) files)


Create an index.html file similar to the following

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
        “http://www.w3.org/TR/html4/loose.dtd”&gt;
<html>
<head>
<title>My Cool app</title>
</head>
<body>
<ul>
    <li><a href=”http://mycoolapp/build/distribution.mobileprovision”&gt;
                Install Example Provisioning File</a></li>
    <li><a href=”itms-services://?action=download-manifest&url=http://mycoolapp/build/app.plist”>
                Install Example Application</a></li>
</ul>
</body>
</html>

Check whether the app.plist contain the full url that points to the .ipa file

Place the files in the server (http://mycoolapp/build/)

Launch the browser in the device and point to http://mycoolapp/build/index.html
Download the provisioning profile and the application.

Reference:

http://jeffreysambells.com/posts/2010/06/22/ios-wireless-app-distribution/

http://www.paradeofrain.com/2010/11/taking-the-pain-out-of-ad-hoc-testing/

Blogged with the Flock Browser

Tags: , , , , , ,