跳到主要內容

發表文章

目前顯示的是 11月, 2015的文章

coffee

                                       

[iOS] Log file for iOS

目的︰用檔案記錄log,以時間組成檔名(yyyyMMddHHmmss),只保留7天 做法︰ 1. 使用XCGLogger來記錄log 2. 每次APP啟動時,檢查log檔案是否有超過7天的,超過就刪除 // AppDelegate.swift import XCGLogger struct MyVariables { static let logger = XCGLogger.defaultInstance() static let documentsPath = NSHomeDirectory() + "/Documents" } class AppDelegate: UIResponder, UIApplicationDelegate { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // 清除7天前的log檔 cleanOldLogFile() // 產生此次log的檔名 let postFixFormatter = NSDateFormatter() postFixFormatter.dateFormat = "yyyyMMddHHmmss" postFixFormatter.locale = NSLocale.currentLocale() let logFileName = "Ticket_" + postFixFormatter.stringFromDate(NSDate()) + ".log" let logFileWithFullPath = MyVariables.documentsPath.stringByAppendingString("/\(logFileName)") let dateFormatter = NSDateFormatter

[iOS] Google Ad 新增 插頁式 廣告

Google 官方 的 教學 怪怪的 不work https://developers.google.com/admob/ios/interstitial?hl=zh-tw   以下目的為加入插頁式廣告,廣告在該頁面載入時會顯示,關閉後會啟動計時器,在30秒後再自動開啟   // CSPViewController.h @import GoogleMobileAds; @interface CSPViewController : UIViewController @end // CSPViewController.m @interface CSPViewController () @property(nonatomic, strong) GADInterstitial *interstitial; @end @implementation CSPViewController{ NSTimer *timer; } - (void)viewDidLoad{ // ... // 加入插入式廣告 self.interstitial = [self createAndLoadInterstitial]; } - (GADInterstitial *)createAndLoadInterstitial { GADInterstitial *interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"ca-app-pub-6497987983526708/719163474"]; interstitial.delegate = self; [interstitial loadRequest:[GADRequest request]]; return interstitial; } - (void)interstitialDidReceiveAd:(GADInterstitial *)ad { [self.interstitial presentFromRootViewController:self]; } - (void)interstitialDidDismissScreen:(GADInter

[iOS] 打分數 的 功能

今天 User 要求要做 “幫我們打個分數吧” 的功能 這應該只是在 click 後 打開 appStore 來 打分數 查了一下 open url 的方式 https://developer.apple.com/library/ios/qa/qa1629/_index.html // Objective-C NSString *iTunesLink = @“itms://itunes.apple.com/us/app/apple-store/id375380948?mt=8"; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]]; // Swift UIApplication.sharedApplication().openURL(NSURL(string: "itms://itunes.apple.com/us/app/tai-gu-ying-shou-fen-xi/id986799180?mt=8")!)   Url Format itms-apps://itunes.apple.com/app/idAPP_ID ex: itms-apps://itunes.apple.com/app/id986799180     取得iTunes url 的方式 1.Launch iTunes on your computer. 2.Search for the item you want to link to. 3.Right-click or control-click on the item's name in iTunes, then choose "Copy iTunes Store URL" from the pop-up menu. 4.In your application, create an NSURL object with the copied iTunes URL, then pass this object to UIApplication' s openURL: method to open your item in the App Store.

[iOS] Auto Layout 筆記

  Autolayout 中的 百分比 宽度 http://maogm.com/blog/percentage-width-in-autolayout.html 這招太實用啦 1.先設定該元件與父元件Equal Width的Constraint 2.再將該Constraint的Multiplier設定需要的比例(ex: 0.5,表示50%)   为iPhone6设计自适应布局(一) http://www.devtalking.com/articles/adaptive-layout-for-iphone6-1/   SnapKit http://snapkit.io/docs/ 居中 let view1 = UIView() view.addSubview(view1) view1.snp_makeConstraints{(make)->Void in make.edges.equalTo(view).insets(UIEdgeInsetsMake(20, 20, 20, 20)) } 等宽 let view2 = UIView() let view3 = UIView() view1.addSubview(view2) view1.addSubview(view3) view1.addSubview(view4) view2.snp_makeConstraints{(make)->Void in make.top.equalTo(view1.snp_top).offset(20) make.width.equalTo(view3) make.left.equalTo(view1.snp_left).offset(20) make.right.equalTo(view3.snp_left).offset(-20) make.height.equalTo(200) } view3.snp_makeConstraints{(make)->Void in make.top.equalTo(view1.snp_top).offset(20) make.width.equalTo(view2) make.right.equalTo(view1.snp_