iOS Yahoo APIs

如果有人需要使用Yahoo Weather, GEO location api可以直接拿來使用,由於剛好需要使用,就順便寫了,使用方式非常的簡單
//yahoo weather
NSLog(@"%@", [YahooAPI yahooAPIWeatherWithWOEID:@"12703518"]);
NSLog(@"%@", [YahooAPI yahooAPIWeatherWithWOEID:@"12703518" unit:YAHOO_WEATHER_UNIT_CELSIUS]);
NSLog(@"%@", [YahooAPI yahooAPIWeatherWithWOEID:@"12703518" unit:YAHOO_WEATHER_UNIT_FAHRENHEIT]);
//yahoo woeid
NSLog(@"%@", [YahooAPI yahooAPIWOEIDWithLatitude:25.049826 Longitude:121.572586]);
NSLog(@"%@", [YahooAPI yahooAPIWOEIDWithAddress:@"台北市大安區敦化南路二段267號"]);

歡迎順手取用 - https://github.com/IskenHuang/YahooLibrary


Reference
YQL Console - http://developer.yahoo.com/yql/console/#h=select%20*%20from%20weather.forecast%20where%20woeid%3D2502265
Yahoo Place Finder - http://developer.yahoo.com/geo/placefinder/

iOS6 AddressBook list

使用iOS6 Addressbook的Sample,使用前別忘了先
"#import <AddressBook/Addressbook.h>"

-(void) grantAddressBook{
// Request authorization to Address Book
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
// First time access has been granted, add the contact
[self getContentList:addressBookRef];
});
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
// The user has previously given access, add the contact
[self getContentList:addressBookRef];
}
else {
// The user has previously denied access
// Send an alert telling user to change privacy setting in settings app
}
}
-(void) getContentList:(ABAddressBookRef)addressBookRef{
CFArrayRef arrayOfEntries = ABAddressBookCopyArrayOfAllPeople(addressBookRef);
CFIndex countOfEntries = CFArrayGetCount(arrayOfEntries);
for (int i=0; i!=countOfEntries; i++) {
NSLog(@"------------------------ [%d] ------------------------", i);
ABRecordRef currentRecord = CFArrayGetValueAtIndex(arrayOfEntries, i);
//iamge
NSData *imageData = (__bridge_transfer NSData*)ABPersonCopyImageData(currentRecord);
UIImage *image = [[UIImage alloc] initWithData:imageData];
NSLog(@"image = %@", image);
//last
NSString *lastName = (__bridge_transfer NSString *)ABRecordCopyValue(currentRecord, kABPersonLastNameProperty);
if (lastName)
NSLog(@"lastName:%@", lastName);
//firstname
NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(currentRecord, kABPersonFirstNameProperty);
if (firstName)
NSLog(@"firstName:%@", firstName);
//nickname
NSString *nickName = (__bridge_transfer NSString *)ABRecordCopyValue(currentRecord, kABPersonNicknameProperty);
if (nickName)
NSLog(@"nickName:%@", nickName);
//middlename
NSString *middlename = (__bridge_transfer NSString*)ABRecordCopyValue(currentRecord, kABPersonMiddleNameProperty);
if(middlename)
NSLog(@"middlename:%@", nickName);
//prefix
NSString *prefix = (__bridge_transfer NSString*)ABRecordCopyValue(currentRecord, kABPersonPrefixProperty);
if(prefix)
NSLog(@"prefix:%@", prefix);
//suffix
NSString *suffix = (__bridge_transfer NSString*)ABRecordCopyValue(currentRecord, kABPersonSuffixProperty);
if(suffix)
NSLog(@"suffix:%@", suffix);
//firstname phonetic
NSString *firstnamePhonetic = (__bridge_transfer NSString*)ABRecordCopyValue(currentRecord, kABPersonFirstNamePhoneticProperty);
if(firstnamePhonetic != nil)
NSLog(@"firstnamePhonetic : %@", firstnamePhonetic);
//lastname phonetic
NSString *lastnamePhonetic = (__bridge_transfer NSString*)ABRecordCopyValue(currentRecord, kABPersonLastNamePhoneticProperty);
if(lastnamePhonetic != nil)
NSLog(@"lastnamePhonetic : %@", lastnamePhonetic);
//middlename phonetic
NSString *middlenamePhonetic = (__bridge_transfer NSString*)ABRecordCopyValue(currentRecord, kABPersonMiddleNamePhoneticProperty);
if(middlenamePhonetic != nil)
NSLog(@"middlenamePhonetic : %@", middlenamePhonetic);
//jobtitle
NSString *jobtitle = (__bridge_transfer NSString*)ABRecordCopyValue(currentRecord, kABPersonJobTitleProperty);
if (jobtitle)
NSLog(@"jobtitle : %@", jobtitle);
//Organization
NSString *organization = (__bridge_transfer NSString*)ABRecordCopyValue(currentRecord, kABPersonOrganizationProperty);
if(organization)
NSLog(@"organization : %@", organization);
//department
NSString *department = (__bridge_transfer NSString*)ABRecordCopyValue(currentRecord, kABPersonDepartmentProperty);
if(department)
NSLog(@"organization : %@", organization);
//birthday
NSDate *birthday = (__bridge_transfer NSDate*)ABRecordCopyValue(currentRecord, kABPersonBirthdayProperty);
if(birthday)
NSLog(@"birthday : %@", birthday);
//note
NSString *note = (__bridge_transfer NSString*)ABRecordCopyValue(currentRecord, kABPersonNoteProperty);
if(note)
NSLog(@"note : %@", note);
//create at
NSString *firstknow = (__bridge_transfer NSString*)ABRecordCopyValue(currentRecord, kABPersonCreationDateProperty);
if(firstknow)
NSLog(@"firstknow : %@", firstknow);
//update at
NSString *lastknow = (__bridge_transfer NSString*)ABRecordCopyValue(currentRecord, kABPersonModificationDateProperty);
if(lastknow)
NSLog(@"lastknow : %@", lastknow);
//Phone
ABMultiValueRef phone = ABRecordCopyValue(currentRecord, kABPersonPhoneProperty);
for(CFIndex x=0; x!=ABMultiValueGetCount(phone); x++) {
NSString *phoneLabel = (__bridge_transfer NSString *)ABMultiValueCopyLabelAtIndex(phone, x);
if ([phoneLabel isEqualToString:(__bridge_transfer NSString *)kABPersonPhoneMobileLabel]) {
NSLog(@"Cell phone:%@", (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phone, x));
}
if ([phoneLabel isEqualToString:(__bridge_transfer NSString *)kABPersonPhoneIPhoneLabel]) {
NSLog(@"iPhone:%@", (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phone, x));
}
if ([phoneLabel isEqualToString:(__bridge_transfer NSString *)kABPersonPhoneMainLabel]) {
NSLog(@"Main phone:%@", (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phone, x));
}
if ([phoneLabel isEqualToString:(__bridge_transfer NSString *)kABPersonPhoneHomeFAXLabel]) {
NSLog(@"Home Fax:%@", (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phone, x));
}
if ([phoneLabel isEqualToString:(__bridge_transfer NSString *)kABPersonPhoneWorkFAXLabel]) {
NSLog(@"Work Fax:%@", (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phone, x));
}
if ([phoneLabel isEqualToString:(__bridge_transfer NSString *)kABPersonPhoneOtherFAXLabel]) {
NSLog(@"Other Fax:%@", (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phone, x));
}
if ([phoneLabel isEqualToString:(__bridge_transfer NSString *)kABPersonPhonePagerLabel]) {
NSLog(@"Pager:%@", (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phone, x));
}
}
for (int k = 0; k<ABMultiValueGetCount(phone); k++)
{
//phone label
NSString * personPhoneLabel = (__bridge_transfer NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phone, k));
//phone number
NSString * personPhone = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(phone, k);
NSLog(@"%@:%@", personPhoneLabel, personPhone);
}
//Email
ABMultiValueRef mail = ABRecordCopyValue(currentRecord, kABPersonEmailProperty);
for(CFIndex x=0; x!=ABMultiValueGetCount(mail); x++) {
NSLog(@"E-Mail:%@", (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(mail, x));
}
//Address
ABMultiValueRef address = ABRecordCopyValue(currentRecord, kABPersonAddressProperty);
for(CFIndex x=0; x!=ABMultiValueGetCount(address); x++) {
NSString* addressLabel = (__bridge_transfer NSString *)ABMultiValueCopyLabelAtIndex(address, x);
BOOL home = [addressLabel isEqualToString:(__bridge_transfer NSString *)kABHomeLabel];
BOOL work = [addressLabel isEqualToString:(__bridge_transfer NSString *)kABWorkLabel];
BOOL other = [addressLabel isEqualToString:(__bridge_transfer NSString *)kABOtherLabel];
NSLog(@"%d || %d || %d", home, work, other);
NSDictionary* personAddress =(__bridge_transfer NSDictionary *)ABMultiValueCopyValueAtIndex(address, x);
NSLog(@"Country:%@", [personAddress valueForKey:(__bridge_transfer NSString *)kABPersonAddressCountryKey]);
NSLog(@"Zipcode:%@", [personAddress valueForKey:(__bridge_transfer NSString *)kABPersonAddressZIPKey]);
NSLog(@"City:%@", [personAddress valueForKey:(__bridge_transfer NSString *)kABPersonAddressCityKey]);
NSLog(@"State:%@", [personAddress valueForKey:(__bridge_transfer NSString *)kABPersonAddressStateKey]);
NSLog(@"Street:%@", [personAddress valueForKey:(__bridge_transfer NSString *)kABPersonAddressStreetKey]);
NSLog(@"Country code:%@", [personAddress valueForKey:(__bridge_transfer NSString *)kABPersonAddressCountryCodeKey]);
}
//url
ABMultiValueRef url = ABRecordCopyValue(currentRecord, kABPersonURLProperty);
for (int m = 0; m < ABMultiValueGetCount(url); m++)
{
//urlLabel
NSString * urlLabel = (__bridge_transfer NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(url, m));
//url conent
NSString * urlContent = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(url,m);
NSLog(@"%@ : %@", urlLabel, urlContent);
}
//IM
ABMultiValueRef instantMessage = ABRecordCopyValue(currentRecord, kABPersonInstantMessageProperty);
for (int l = 1; l < ABMultiValueGetCount(instantMessage); l++)
{
//IM Label
NSString* instantMessageLabel = (__bridge_transfer NSString*)ABMultiValueCopyLabelAtIndex(instantMessage, l);
NSLog(@"instantMessageLabel : %@", instantMessageLabel);
NSDictionary* instantMessageContent =(__bridge_transfer NSDictionary*) ABMultiValueCopyValueAtIndex(instantMessage, l);
NSString* username = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageUsernameKey];
if(username != nil)
NSLog(@"username : %@", username);
NSString* service = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageServiceKey];
if(service != nil)
NSLog(@"service : %@", service);
}
//date
ABMultiValueRef dates = ABRecordCopyValue(currentRecord, kABPersonDateProperty);
int datescount = ABMultiValueGetCount(dates);
for (int y = 0; y < datescount; y++)
{
//dates Label
NSString* datesLabel = (__bridge_transfer NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(dates, y));
//dates
NSString* datesContent = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(dates, y);
NSLog(@"%@ : %@", datesLabel, datesContent);
}
//kind
CFNumberRef recordType = ABRecordCopyValue(currentRecord, kABPersonKindProperty);
if (recordType == kABPersonKindOrganization) {
// it's a company
NSLog(@"it's a company\n");
} else {
// it's a person, resource, or room
NSLog(@"it's a person, resource, or room\n");
}
}
NSLog(@"Total:%ld", countOfEntries);
CFRelease(arrayOfEntries);
}
view raw AddressBook.m hosted with ❤ by GitHub


Reference: here: http://stackoverflow.com/a/12648938/480415

iOS Multiple target in the same project

如果新增Target在同一專案下可利用以下方式來區隔Target,避免需要維護兩份Code的成本

選擇 target -> Build Settings -> 搜尋 "preprocessor Macros"

*此範例為新增一個lite的版本
*Debug & Release 兩個版本都要加入

完成後在需要判斷是否為pro或lite版本方式
#ifdef LITE
//lite version
//your code here
#else
//not lite version(i.e. pro)
//your code here
#endif
//-------------------------------------------------------------
#ifndef PRO
//is pro version
//your code here
#else
//not pro version(i.e. lite)
//your code here
#endif
view raw gistfile1.m hosted with ❤ by GitHub


ios project build build number auto increase

xcode自動增加build number

Step1. Add Run Script


Step2. Input Script


如果是增加數字(1, 2, 3, ...... 9, 10, 11, 12, ...)
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"

如果為16進位(1, 2, 3, ...... 9, A, B, C, ...)
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
buildNumber=$(printf "%X" $buildNumber)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"

完成後每次Build就會自動增加Build number

ios tableView cell accessory

TableViewCell的右邊常常會看到個「>」或者其他符號,常見的幾個當然系統內建就有可以參考如下

UITableViewCellAccessoryDisclosureIndicator

UITableViewCellAccessoryDetailDisclosureButton

UITableViewCellAccessoryCheckmark

當然,如果都不需要顯示使用
UITableViewCellAccessoryNone

使用方式如下
[cell setAccessoryType:XXXX]


參考資料
iOS Developer Library - UITableViewCell