每次測試 InApp 總讓我有新的注意事項,發現取得付費資訊正常。
但按下確認要輸入帳號資訊時,一直出現"無法連接 iTunes Store"的錯誤訊息。
結果才發現,要先把設定裡的 apple id 登出,才可使用。
或者直接登入在 iTunes Connect 裡建立好的 tester 帳號亦可。
2013年10月16日 星期三
2013年10月10日 星期四
[iOS] 如何設定 SearchBar 背景色
在 iOS6 以前,加入以下方法即可。
for(UIView *subview in searchBar.subviews)
{
if([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subview removeFromSuperview];
break;
}
}
但在 iOS7 中,要再加下以下方式才可以。
[searchBar setBarTintColor:[UIColor clearColor]];
for(UIView *subview in searchBar.subviews)
{
if([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subview removeFromSuperview];
break;
}
}
但在 iOS7 中,要再加下以下方式才可以。
[searchBar setBarTintColor:[UIColor clearColor]];
2013年9月23日 星期一
[iOS] iOS7 狀態欄無法消失?
//在 root ViewController 中,viewDidload 函式裡增加
if([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)])
{
// iOS 7
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
else
{
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
// 增加此函式
- (BOOL)prefersStatusBarHidden
{
return YES;
}
如此即可相容 iOS6 & iOS7 的情況。
if([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)])
{
// iOS 7
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
else
{
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
// 增加此函式
- (BOOL)prefersStatusBarHidden
{
return YES;
}
如此即可相容 iOS6 & iOS7 的情況。
2013年9月11日 星期三
[iOS] NSMutableArray 排序小記
一般在陣列排序都使用以下方式:
NSSortDescriptor *countSorter = [NSSortDescriptor sortDescriptorWithKey:@"count" ascending:YES];
[self.listData sortUsingDescriptors:[NSArray arrayWithObject:countSorter]];
[countSorter release];
但,發現如果 key 值是整數的話,就要加上 comparator 來判斷才可。
NSSortDescriptor *countSorter = [NSSortDescriptor sortDescriptorWithKey:@"count" ascending:YES comparator:^(id obj1, id obj2)
{
if([obj1 integerValue] > [obj2 integerValue])
{
return (NSComparisonResult)NSOrderedDescending;
}
if([obj1 integerValue] < [obj2 integerValue])
{
return (NSComparisonResult)NSOrderedAscending;
}
return (NSComparisonResult)NSOrderedSame;
}];
[self.listData sortUsingDescriptors:[NSArray arrayWithObject:countSorter]];
[countSorter release];
如果是判斷內容是 NSDate 的話,使用以下方式:
NSSortDescriptor *dateDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:NO];
NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor];
self.listData = [[self.listData sortedArrayUsingDescriptors:sortDescriptors] mutableCopy];
NSSortDescriptor *countSorter = [NSSortDescriptor sortDescriptorWithKey:@"count" ascending:YES];
[self.listData sortUsingDescriptors:[NSArray arrayWithObject:countSorter]];
[countSorter release];
但,發現如果 key 值是整數的話,就要加上 comparator 來判斷才可。
NSSortDescriptor *countSorter = [NSSortDescriptor sortDescriptorWithKey:@"count" ascending:YES comparator:^(id obj1, id obj2)
{
if([obj1 integerValue] > [obj2 integerValue])
{
return (NSComparisonResult)NSOrderedDescending;
}
if([obj1 integerValue] < [obj2 integerValue])
{
return (NSComparisonResult)NSOrderedAscending;
}
return (NSComparisonResult)NSOrderedSame;
}];
[self.listData sortUsingDescriptors:[NSArray arrayWithObject:countSorter]];
[countSorter release];
如果是判斷內容是 NSDate 的話,使用以下方式:
NSSortDescriptor *dateDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:NO];
NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor];
self.listData = [[self.listData sortedArrayUsingDescriptors:sortDescriptors] mutableCopy];
2013年7月4日 星期四
[iOS] NSURLRequest 中 URL 的中文字處理小記
最近把 web link 用 uiwebview 來呈現,發現當 link 有中文字時,NSURLRequest 會無法順利載入,拜讀 google 大大後,找到解決方法,要透過 stringByAddingPercentEscapesUsingEncoding 來將中文字轉換成 percent escaped的字串,記錄如下:
NSString *urlStr = @"http://www.abc.com.tw/中文字.png";
NSString *imageUrlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: imageUrlStr]];
2013年5月6日 星期一
[iOS] pushViewController:animated & popViewControllerAnimated 使用 CATransition 小記
一般常見使用 push&pop ViewController 時,都是向右進入及向左退出。
若要使用其他效果的過場動畫時,可以搭配 CATransition 這個類別來使用。
需要的 framework:QuartzCore
使用方法:
若要使用其他效果的過場動畫時,可以搭配 CATransition 這個類別來使用。
需要的 framework:QuartzCore
使用方法:
CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType:@"oglFlip"];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
UIViewController *viewVC = [[UIViewController alloc] initWithNibName:@"UIViewController_iPhone" bundle:nil];
[self.navigationController pushViewController: viewVC animated:NO];
[self.navigationController.view.layer addAnimation:animation forKey:nil];
[viewVC release];
CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType:@"oglFlip"];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[self.navigationController.view.layer addAnimation:animation forKey:nil];
[self.navigationController popViewControllerAnimated:YES];
PS:要特別注意,push 與 pop ViewController 的順序有不同。
2013年4月18日 星期四
[iOS] InApp 在 iOS5 之後呼叫 paymentWithProductIdentifier 的問題小記
InApp Purchase 是 app developer 很大的收入來源,最近在使用發現原本使用的函式有些許改變,記錄一下:
PS:InApp 目前還無法在模擬器上完整跑完流程,還是乖乖在實機上測試為準。
+ (id)paymentWithProductIdentifier:(NSString *)identifier __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_3_0,__IPHONE_5_0);
在 iOS5.0 前使用的好好,在之後可改由下列方式實作:
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
//宣告 SKProduct *proUpgradeProduct 來儲存收到的付費資訊
SKPayment *payment = [SKPayment paymentWithProduct:proUpgradeProduct];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
PS:InApp 目前還無法在模擬器上完整跑完流程,還是乖乖在實機上測試為準。
訂閱:
文章 (Atom)