예전 버전에서 부터 간단하게 설정하던 것인데, 여기 적어 둡니다.
위와 같이 설정을 하면, 자동으로 idle로 넘어가지 않습니다.
[UIApplication sharedApplication].idleTimerDisabled = NO;
위와 같이 설정을 하면, 자동으로 idle로 넘어가지 않습니다.
[UIApplication sharedApplication].idleTimerDisabled = NO;
NSLog(@"Name: %@", NSLocalizedString(@"Name", @"Name"));
NSLog(@"Name: %@", NSLocalizedString(@"Text", @"Text"));
NSLog(@"MyName: %@", NSLocalizedString(@"MyName", @"Name"));
NSLog(@"MyText: %@", NSLocalizedString(@"MyText", @"Text"));
//h 파일에서.. @property (weak, nonatomic) IBOutlet UILabel *koLabel; //m 파일에서.. self.koLabel.font = [UIFont fontWithName:@"AppleSDGothicNeo-Bold" size:17.0f]; //기본으로 AppleSDGothicNeo이므로 별 차이가 없다.
//h 파일에서.. @property (weak, nonatomic) IBOutlet UILabel *koLabel; //m 파일에서.. self.koLabel.font = [UIFont fontWithName:@"NanumBrush" size:17.0f]; // Naver의 나눔손글씨 붓 폰트가 적용이 되었다.적용한 것을 한번 보면.
//UIFont에서 지원하는 폰트를 알아보자. NSArray *fonts = [UIFont familyNames]; NSLog(@"Available fonts : %@", fonts); //Family Name에서 지원하는 폰트 리스트는 아래 함수로 읽어 올 수 있다. NSArray *fontList = [UIFont fontNamesForFamilyName:_familyFontName];






//접근권한체크하기.
ABAuthorizationStatus status = ABAddressBookGetAuthorizationStatus();
if(status == kABAuthorizationStatusDenied ||
status == kABAuthorizationStatusRestricted)
{
NSString *message;
message = @"연락처에접근할수있는권한이없습니다.
설정 > 개인정보보호 > 연락처에서권한을설정해주세요.";
//NSLog(@"Location Services Disabled");
UIAlertView* addrressBookAlert = [[UIAlertView alloc] initWithTitle:@"Error"
message:message
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[addrressBookAlert show];
}
이 권한은 연락처 일기 등을 할 때, 체크해서 보여줘도 되고, 프로그램이 시작할 때, 체크해서 사용자에게 권한을 변경하도록 요청할 수 있습니다.- (void) prepareAddressBook
{
CFErrorRef error;
myAddressBook = ABAddressBookCreateWithOptions(NULL, &error);
if (myAddressBook == NULL) {
//
if(error == kABOperationNotPermittedByStoreError){
NSLog(@" not permitted by store");
}
/*
else if(error == kABOperationNotPermittedByUserError){
NSLog(@" not permitted by User");
}*/
}
TCContactManager * __weak weakSelf = self; // avoid capturing self in the block
ABAddressBookRequestAccessWithCompletion(myAddressBook,
^(bool granted, CFErrorRef error) {
if (granted) {
weakSelf.friendsList = [weakSelf fetchPeopleInAddressBook:myAddressBook];
NSLog(@" load success: %d", [weakSelf.friendsList count]);
} else {
// Handle the error
NSLog(@" no granted..");
}
});
}
// Return a list of people in address book
- (NSMutableArray*) fetchPeopleInAddressBook:(ABAddressBookRef)addressBook
{
NSMutableArray *list = nil;
CFArrayRef personList = ABAddressBookCopyArrayOfAllPeople(addressBook);
long personCount = CFArrayGetCount(personList);
if( personCount > 0){
NSLog(@" Person Count:%ld", personCount);
if(list == nil)
{
list = [[NSMutableArray alloc] initWithCapacity:personCount];
}
for(int i = 0; i < personCount; i++)
{
ABRecordRef record = CFArrayGetValueAtIndex(personList, i);
TCContactData* contact = [self getContactDataFrom:record];
if(contact != nil && ![list containsObject:contact]){
[list addObject:contact];
}
CFRelease(record);
}
}
CFRelease(personList);
return list;
}
CFArrayRef의 형태로 받아오게 되고, CFArrayGetCount로 읽어온 개수를 알 수 있다.ABRecordID ABRecordGetRecordID ( ABRecordRef record );레코드의 Unique ID를 읽어오는 함수로 현재 레코드의 ID를 읽어올 수 있습니다.
ABRecordType ABRecordGetRecordType ( ABRecordRef record );위에서 각 People이 아닌, 그룹의 리스트를 가져올 수도 있고, Source의 리스트를 받아 올 수도 있어서, 현재 Record의 타입이 뭔지 알수 있어야 합니다.
kABPersonType for person records kABGroupType for group records. kABSourceType for source records.
bool ABRecordSetValue ( ABRecordRef record, ABPropertyID property, CFTypeRef value, CFErrorRef *error );
CFTypeRef ABRecordCopyValue ( ABRecordRef record, ABPropertyID property );
const ABPropertyID kABPersonPhoneProperty; const CFStringRef kABPersonPhoneMobileLabel; const CFStringRef kABPersonPhoneIPhoneLabel; const CFStringRef kABPersonPhoneMainLabel; const CFStringRef kABPersonPhoneHomeFAXLabel; const CFStringRef kABPersonPhoneWorkFAXLabel; const CFStringRef kABPersonPhoneOtherFAXLabel; const CFStringRef kABPersonPhonePagerLabel;그래서, kABPersonPhoneProperty로 읽으면 ABMultiValueRef 형태로 받아오고, 거기에서 위에 값들이 있는지 ABMultiValueCopyLabelAtIndex를 통해서 읽어 올 수 있다. 좀 복잡한데 아래 함수 설명 이후 전화번호 읽는 것을 예제로 보이도록 하겠다.
bool ABRecordRemoveValue ( ABRecordRef record, ABPropertyID property, CFErrorRef *error );
CFStringRef ABRecordCopyCompositeName ( ABRecordRef record );
- (TCContactData*) getContactDataFrom:(ABRecordRef)record
{
ABMultiValueRef phoneRef = ABRecordCopyValue(record, kABPersonPhoneProperty);
NSString* phoneNumber = nil;
int phoneRefCount = ABMultiValueGetCount(phoneRef);
for( int j = 0; j < phoneRefCount; j++)
{
CFStringRef labelRef = ABMultiValueCopyLabelAtIndex(phoneRef, j);
if( CFStringCompare(labelRef, kABPersonPhoneMobileLabel, 0) == kCFCompareEqualTo){
phoneNumber = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phoneRef, j);
break;
}else if( CFStringCompare(labelRef, kABPersonPhoneIPhoneLabel, 0) == kCFCompareEqualTo){
phoneNumber = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phoneRef, j);
break;
}
/*else if( CFStringCompare(labelRef, kABPersonPhoneMainLabel, 0) == kCFCompareEqualTo){
contact.phoneNumber = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phoneRef, j);
break;
}*/
CFRelease(labelRef);
}
if(phoneNumber){
TCContactData* contact = [[TCContactData alloc] init];
contact.name = (__bridge NSString*)ABRecordCopyCompositeName(record);
contact.firstName = (__bridge NSString*)ABRecordCopyValue(record, kABPersonFirstNameProperty);
contact.lastName = (__bridge NSString*)ABRecordCopyValue(record, kABPersonLastNameProperty);
contact.phoneNumber = phoneNumber;
CFDataRef thumbnail = ABPersonCopyImageDataWithFormat(record, kABPersonImageFormatThumbnail);
if(thumbnail != nil)
{
contact.image = [[UIImage alloc] initWithData:(__bridge NSData*)thumbnail];
NSLog(@" Name:%@ has image.", contact.name);
CFRelease(thumbnail);
}
return contact;
}
CFRelease(phoneRef);
return nil;
}
Boolean cameraEnabled = NO;
Boolean photoLibEnabled = NO;
if( [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
cameraEnabled = YES;
}
if( [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
photoLibEnabled = YES;
}
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera];
if ([mediaTypes containsObject:(NSString *)kUTTypeImage]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
picker.allowsEditing = NO;
[self presentViewController:picker animated:YES completion:^{
NSLog(@"presentViewController completion");
}];
}
포토 라이브러리를 사용할 수 있고, 지원하는 타입에 이미지가 있을 경우..
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypePhotoLibrary];
if ([mediaTypes containsObject:(NSString *)kUTTypeImage]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
picker.allowsEditing = NO;
[self presentViewController:picker animated:YES completion:^{
NSLog(@"presentViewController completion");
}];
}
아래는 이미지를 선택하거나 사진을 찍은 후에, UIImagePickerControllerDelegate로 받는 함수들이다.
dismissImagePicker, Cancel, didFinishPickingMediaWithInfo함수가 있다.
- (void)dismissImagePicker
{
[self dismissViewControllerAnimated:YES completion:^{
NSLog(@"dismissViewControllerAnimated completion: ");
}];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissImagePicker];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//Editing된 이미지를 가져온다.
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
//Edit하지 않았으면 원 이미지를 가져온다.
if (!image) image = [info objectForKey:UIImagePickerControllerOriginalImage];
if (image) {
[self setImage:image]; //가져온 이미지를 처리한다.
}
[self dismissImagePicker];
}
#define STRING_TITLE @"I have a question."
#define STRING_CANCEL @"Cancel"
#define STRING_QUESTION1 @"What is your name?"
#define STRING_QUESTION2 @"Who you are?"
#define STRING_QUESTION3 @"I have no question."
#define STRING_QUESTION4 @"Question4"
#define STRING_QUESTION5 @"Question5"
#define STRING_QUESTION6 @"Question6"
#define STRING_QUESTION7 @"Question7"
- (IBAction)askQuestion:(id)sender
{
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:STRING_TITLE
delegate:self
cancelButtonTitle:STRING_CANCEL
destructiveButtonTitle:STRING_QUESTION1
otherButtonTitles:STRING_QUESTION2, STRING_QUESTION3, STRING_QUESTION4, STRING_QUESTION5, STRING_QUESTION6,STRING_QUESTION7, nil];
[actionSheet showInView:self.view];
}
#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *choice = [actionSheet buttonTitleAtIndex:buttonIndex];
if(buttonIndex == [actionSheet destructiveButtonIndex]) {
//?
}
if([choice isEqualToString:STRING_QUESTION1]){
//
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Question"
message:STRING_QUESTION1
delegate:self
cancelButtonTitle:STRING_CANCEL
otherButtonTitles: nil];
[alert show];
}else if([choice isEqualToString:STRING_QUESTION2]){
//
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Question"
message:STRING_QUESTION2
delegate:self
cancelButtonTitle:STRING_CANCEL
otherButtonTitles: nil];
[alert show];
}else if([choice isEqualToString:STRING_CANCEL]){
//Do Nothing..
}
}
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"actionSheet: didDismissWithButtonIndex:%d", buttonIndex);
}
-(void) actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"actionSheet: willDismissWithButtonIndex:%d", buttonIndex);
}
- (UIImage*)getResizedImage:(UIImage*)image inBound:(CGSize)size
{
if (NULL != UIGraphicsBeginImageContextWithOptions)
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
else
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
// Flip the context because UIKit coordinate system is upside down to Quartz coordinate system
CGContextTranslateCTM(context, 0.0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);
// Draw the original image to the context
CGContextSetBlendMode(context, kCGBlendModeCopy);
CGContextDrawImage(context, CGRectMake(0.0, 0.0, size.width, size.height), image.CGImage);
// Retrieve the UIImage from the current context
UIImage *imageOut = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageOut;
}
#import <QuartzCore/QuartzCore.h>
..
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageView.layer.shadowColor = [UIColor blackColor].CGColor; //그림자 색상
self.imageView.layer.shadowOffset = CGSizeMake(5.0, 5.0); //그림자 Offset
self.imageView.layer.shadowOpacity = 0.9f; //투명도
self.imageView.layer.shadowRadius = 2.0f; //그림자 코너 부분
self.imageView.layer.backgroundColor = [UIColor blackColor].CGColor;
}
#import <QuartzCore/QuartzCore.h> .. UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage ....]]; imageView.layer.cornerRadius = 5.0; //테두리가 라운드가 된다. imageView.layer.masksToBounds = YES; //테두리의 배경을 투명하게 imageView.layer.borderColor = [UIColor whiteColor].CGColor; //테두리 색상 imageView.layer.borderWidth = 3.0; //테두리의 두께