2015年4月18日 星期六

XCode6.3惱人的bug

升到XCode 6.3發現一個惱人的Bug

明明就有一隻手機是ios 8.1.2版

project設定 iOS Deployment Target 為 8.0版本

照理說8.0以上的手機都要可以發佈至實機上(以正確的憑證狀況下),

但升到XCode6.3 卻無法傳app至8.1.2、8.2 的iOS手機

而iOS 8.3的手機卻可以!!

不可能要我把所有裝置都升級到8.3

這個bug 是你無法選擇你的裝置,

會出現 ineligible Devices.



後來找到解法!!!!

只要你到Product→Destionation→選擇你的裝置


左上角就會直接跳到你的手機,就可以發佈了.....|||||||


2015年3月23日 星期一

解決Xcode外掛無法使用問題

解決xcode下外掛無法使用

到以下目錄

~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/

找到你要的外掛 打開套件內容

選擇info.plist檔,

於DVTPluginCompatibilityUIDs加入

XCodde 6.3.2
E969541F-E6F9-4D25-8158-72DC3545A6C6
並執行
find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add `defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID`

XCode 6.3
9F75337B-21B4-4ADC-B558-F9CADF7073A7
Xcode 6.2
A16FF353-8441-459E-A50C-B071F53F51B7

Xcode 6GM:
C4A681B0-4A26-480E-93EC-1218098B9AA0


2015年3月12日 星期四

iOS Container view與Parent UIViewController的溝通



若parent裡要呼叫container裡面的屬性




self.ChildViewController.yourProperty = yourValue




若container要呼叫parent的屬性:




((YourParentViewControllerClassType *)self.parentViewController).yourParentProperty = TheValueYouWant;

2015年3月2日 星期一

UIContainer View呼叫Parent ViewController屬性與傳值

UIContainer VIew 傳值給ParentViewController




主要是選擇使用delegate的方式,

在ParentViewController.h



#import 
#import "ChildViewController.h"

@interface ViewController : UIViewController<ChildViewControllerDelegate>

@property (weak, nonatomic) IBOutlet UITextField *parentTF;

@end


ParentUIViewController .m  檔

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([segue.identifier isEqualToString:@"mySegue"])
    {
        ChildViewController *cVC = segue.destinationViewController;
        cVC.delegate = self;
    }
}

-(void) done:(NSString *)someText andChildBtn:(UIButton *)childBtn
{
    self.parentTF.text = someText;
    [childBtn setTitle:@"changed" forState:UIControlStateNormal];
    [self.view setBackgroundColor:[UIColor darkGrayColor]];
}
@end


而在 ChildViewController.h 要宣告定義好protocol讓UIViewController能夠處理你要他做的事情



#import <UIKit/UIKit.h>
// 傳到到另個 ViewController ,所以自己要先定義protocol
@protocol ChildViewControllerDelegate <NSObject>

-(void)done:(NSString*)someText andChildBtn:(UIButton*)childBtn;

@end

@interface ChildViewController : UIViewController

@property(nonatomic,assign) id<ChildViewControllerDelegate> delegate;

@property (weak, nonatomic) IBOutlet UIButton *passValueBtn;
@property (weak, nonatomic) IBOutlet UITextField *childTF;
- (IBAction)passValueAction:(id)sender;
@end



然後.m檔去呼叫delegate方法

#import "ChildViewController.h"

@implementation ChildViewController

- (IBAction)passValueAction:(id)sender {
    
    [self.delegate done:self.childTF.text andChildBtn:self.passValueBtn];
}
@end


這樣就可以透過container view controller去傳值給parentviewcontroller

而還有夠簡易的方式是

直接由container view controller去修改parent view controller的值

例如


 ((ViewController*)self.parentViewController).lb.text =[NSString stringWithFormat:@"%ld",indexPath.row];

以上是由container view 呼叫 parent view的屬性

2015年2月12日 星期四

Objective-C 字串比較

一般自定常數的方法有兩種,

1.  在header(.h)檔

FOUNDATION_EXPORT NSString * const MY_NAME;
FOUNDATION_EXPORT NSString * const MY_GIRLFRIEND_NAME;

於.m檔

NSString * const MY_NAME = @"James";
NSString * const MY_GIRLFRIEND_NAME = @"Stella";

2. 另一種定義常數的方法為:

#define MY_NAM @"James"
#define MY_GIRLFRIEND_NAME  @"Stella"

這兩種方法在檢查字串時,第一種可以使用(StringInstance == MY_NAME )來比較,

而使用define則是使用([StringInstance isEqualToString:MY_NAME]) 來比較。

第一種直接比較是使用pointer address,第二種比較則是比較每個字元是否相等。


2015年1月26日 星期一

gen_entitlements.py: No such file or directory實機報錯

今天要把別的廠商的專案進行測試

但拿到專案檔一直無法傳到手機上,

以為是憑證哪出了問題,但後來發現不是!

錯誤訊息部份如下

line 4: /Applications/Xcode.app/Contents/Developer/iphoneentitlements/gen_entitlements.py: No such file or directory




後來發現這個是之前公司在作假憑證的run script出了問題

只要到build phase裡刪除 run script

再使用正確的debug憑證去發佈至手機即可


2014年12月9日 星期二

啟用Watch App Simulator

目前測試 apple 最新的 apple watch 可以透過XCode 6.2 beta版

apple watch的project是要綁在手機上的專案,

所以watch app其實只是手機app的延伸,

若你今天要啟用apple watch simulator的話,

只要在xcode的target選擇watch app




然後按下compile

模擬器就會跑出來囉!

若你發現只有手機模擬器出現的話,

你可以在模擬器的工具列

Hardware→External Displays→選到最下方的Apple Watch

這樣Apple watch的simulator就會跑出來囉!