Translate

2015年12月20日 星期日

Watchkit app fails to launch only on ipad

Watchkit app fails to launch only on ipad
What happens is that turning on the HealthKit capability on the Apple Watch extension adds a value healthkitto the UIRequiredDeviceCapabilities array of that same target.

For some strange reason that value prevents the app from launching properly on any iPad device. Manually removing the healthkit value from the Apple Watch extension target plist fixed the issue and submission was successful.

Xcode Could not find Developer Disk Image

Could not find Developer Disk Image
In case of same problem for better understanding how to fix do next:
1.Go to /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
2.Go to /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSup‌​port
3.Copy folder iOS 9.2 in another folder
4.Restart Xcode

2015年8月4日 星期二

Embedded Binary Validation Utility Error error: WatchKit apps must have a deployment target equal to iOS 8.2 (was 8.3)

Stack Overflow
Select your project settings and go to "TARGETS". Click on your Watch Kit App, select Build Settings. For the key "iOS Deployment Target" you should find "iOS 8.3". For some reason Xcode 6.3 Beta 4 wants to have this on "iOS 8.2" for "Debug" and "Release". Now your project should build as expected.

2015年7月31日 星期五

Custom URL Scheme

參考[iOS] 客製化 URL Scheme (Custom URL Scheme)

播放影片可以直向橫向

參考[iOS] 在WebView播放Youtube影片旋轉 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if ([[window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]] || [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"XCDYouTubeVideoPlayerViewController")] || [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"XCDYouTubeVideoPlayerViewController")]) { return UIInterfaceOrientationMaskAll; } else { if ([[window.rootViewController presentedViewController] isKindOfClass:[UINavigationController class]]) { // look for it inside UINavigationController UINavigationController *nc = (UINavigationController *)[window.rootViewController presentedViewController]; // is at the top? if ([nc.topViewController isKindOfClass:[MPMoviePlayerViewController class]]) { return UIInterfaceOrientationMaskAll; // or it's presented from the top? } else if ([[nc.topViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]]) { return UIInterfaceOrientationMaskAll; } } } return UIInterfaceOrientationMaskPortrait; }

MPMoviePlayerController play youtube video

github XCDYouTubeKit

iOS 本地化圖片

ios-succinctly-localization

creating-multi-lingual-apps

CustomPhotoAlbum

CustomPhotoAlbum

XCode6 製作Static Framework

XCode6 製作Static Framework

2015年7月23日 星期四

Xcode 6 projectname-prefix-pch

參考文章
Without the question if it is proper or not, you can add PCH file manually:

1.Add new PCH file to the project: New file > Other > PCH file.

2.At the Target's Build Settings option, set the value of Prefix Header to your PCH file name, with the project name as prefix (i.e. for project named TestProject and PCH file named MyPrefixHeaderFile, add the value TestProject/MyPrefixHeaderFile.pch to the plist).

TIP: You can use things like $(SRCROOT) or $(PROJECT_DIR) to get to the path of where you put the .pch in the project.

3.At the Target's Build Settings option, set the value of Precompile Prefix Header to YES.

How to print out the method name and line number and conditionally disable NSLog?

參考文章
#ifdef DEBUG # define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); #else # define DLog(...) #endif #define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); #ifdef DEBUG # define ULog(fmt, ...) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; } #else # define ULog(...) #endif

2015年7月17日 星期五

得到UIView中某个非子视图在UIView中的位置

轉帖文章
因為很少用到但是又記不起來特地來記錄一下
使用 convertRect: fromView: 或者 convertRect: toView: 例如一个视图控制器的view中有一个UITableView,UITableView的某个cell中有个UITextField,想要得到UITextField在view中的位置,就要靠上面的两个方法了。 用 CGRect rect = [self.view convertRect:textField.frame fromView:textField.superview]; 或者 CGRect rect = [textField.superview convertRect:textField.frame toView:self.view]; 进行转换都可以。

2015年7月16日 星期四

Auto resizing UIWebView content do not fit the frame

- (void)webViewDidFinishLoad:(UIWebView *)webView { CGSize contentSize = [webView sizeThatFits:CGSizeZero]; CGSize viewSize = webView.frame.size; CGFloat rw = viewSize.width / contentSize.width; webView.scrollView.minimumZoomScale = rw; webView.scrollView.maximumZoomScale = rw; webView.scrollView.zoomScale = rw; }

iOS如何设置app支持文件共享

轉帖Ray
轉帖iOS如何设置app支持文件共享
在应用程序的Info.plist文件中添加UIFileSharingEnabled键,并将键值设置为YES

2015年6月11日 星期四

目前为止Apple移动设备默认指令集(2014.8.22)

目前为止Apple移动设备默认指令集(2014.8.22) ------------------------------------------------------------------------------------- armv6 设备: iPhone, iPhone2, iPhone3G, 第一代、第二代 iPod Touch armv7 设备: iPhone3GS, iPhone4, iPhone4S iPad, iPad2, iPad3(The New iPad), iPad mini iPod Touch 3G, iPod Touch4 armv7s设备: iPhone5, iPhone5C, iPad4(iPad with Retina Display) arm64 设备: iPhone5S, iPad Air, iPad mini2(iPad mini with Retina Display) http://www.cocoachina.com/ios/20140915/9620.html XCode中与指令集相关的选项(Build Settings 面板下 Architectures): Architectures: 指明选定Target要求被编译生成的二进制包所支持的指令集支持指令集是通过编译生成对应的二进制数据包实现的,如果支持的指令集数目有多个,就会编译出包含多个指令集代码的数据包,从而会造成最终编译生成的包很大。 Valid Architectures: 指明可能支持的指令集并非Architectures列表中指明的指令集都会被支持,Valid Architectures限制可能被支持的指令集的范围,即Valid Architectures和Architectures列表的交集,才是XCode最终生成二进制包所支持的指令集。 比如,将Architectures支持arm指令集设置为:armv7,armv7s,对应的Valid Architectures的支持的指令集设置为:armv7s,arm64,那么此时,XCode生成二进制包所支持的指令集只有armv7s 。 Build Active Architecture Only: 指明是否只编译当前连接设备所支持的指令集 该选项起作用的条件有两个,必须同时满足才会起作用: 1. 其值设置为YES 2. XCode成功连接调试设备 假定我们将Build Active Architecture Only值设置为YES,同时XCode连接上手机iPhone5S(匹配指令集arm64) 1. 第一种情况 Architectures: armv7, armv7s, arm64 ValidArchitectures: armv6, armv7s, arm64 生成二进制包支持的指令集: arm64 2. 第二种情况 Architectures: armv6, armv7, armv7s Valid Architectures: armv6, armv7s, arm64 生成二进制包支持的指令集: armv7s 3. 第三种情况 Architectures: armv6, armv7 Valid Architectures: armv6, armv7s, arm64 生成二进制包支持的指令集: armv7 4. 第四种情况 Architectures: armv6 Valid Architectures: armv6, armv7s, arm64 生成二进制包支持的指令集: 虽然编译成功了,但是并没有任何目标生成, 因为从XCode4.5开始,就不再支持armv6指令集,所以列表中写了也是白写。 5. 第五种情况 Architectures: armv7, armv7s, arm64 Valid Architectures: armv7,armv7s 生成二进制包支持的指令集: 编译出错信息 No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=arm64, VALID_ARCHS=armv7 armv7s) 可以看出:当Build Active Architecture Only起作用时: 连接的手机指令集匹配是由高到低(arm64 > armv7s > armv7)依次匹配的。 如连接手机为iPhone5S,其默认指令集为arm64,若Architectures列表为armv7, armv7s,则会选取armv7s指令集为目标指令集,如果此时Valid Architectures列表中包含该指令集,则成功生成的二进制包只支持armv7s指令集,若alid Architectures列表不包含此指令集,则编译将会出错: No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=armv7s, VALID_ARCHS=armv7 arm64) 同样的,若Architectures列表为armv7,则会选取armv7作为目标指令集,若Valid Architectures列表中包含了armv7指令集,则能够成功生成二进制包,其支持的指令集只有armv7,若Valid Architectures列表中不包含armv7,则编译失败。 建议:通常Debug模式设置值为Yes,Release模式设置为No

記錄一下如何在本來的專案上新增Watch App Target

1.Add Apple Watch target to your project (New->Target->Apple Watch->Watch App)

2.Go to iOS Simulator -> Hardware -> External displays and select any Apple Watch options

3.Choose '[your project] Watch App' target and Run

Custom URL Scheme

method

Open your app from from safari browser or other app. just setting URL type--> setting URL schemes like bellow

Xcode6 如何去除icon高光


Images.xcassets -> AppIcon -> iOS icon is pre-rendered(如图所示)

iphone6和6plus模拟器键盘不弹出问题

在xcode6中, 模拟器中的键盘和电脑的键盘可以进行绑定or解除绑定,打开模拟器,在最上面的菜单栏中,选择hardware,然后选择keyboards,有三个选项, 依次都勾选就行了。(注意:第三个选项在点击之后,实际已勾上了,但显示未勾上,但实际已经奏效了,这可能是xcode6的一个显示上的bug)

NSLog NSData Length to bytes

NSLog(@"File size is : %.2f MB",(CGFloat)myData.length/1024.0f/1024.0f);

Or for OS X 10.8+ and iOS 6+

NSLog(@"%@",[NSByteCountFormatter stringFromByteCount:myData.length countStyle:NSByteCountFormatterCountStyleFile]);

2015年4月14日 星期二

Xcode 6.3 not displaying memory report


I have resolved disabling Memory Guard diagnostic in the Scheme. From Xcode: Menu Product -> Scheme -> Edit Scheme... -> Diagnostic Tab -> uncheck all Guard options

If still doesn't work, try to disable (if enabled) the "Enable Zombie Object" checkbox

solve

2015年3月31日 星期二

Reachability

常常出現這個錯誤
+ (Reachability*) reachabilityWithAddress: (const struct sockaddr_in*) hostAddress;
*declaration of 'struct sockaddr_in*' will not be visible outside of this function*
看了很討厭後來再找到解決方法
解答在這
import netinet/in.h
import <>打不上去所以請自己<>

2015年3月30日 星期一

UILabel and UITextView

最近遇到一個問題
字串相同字型大小相同
在UILabel跟UITextView呈現的size不一樣
後來在這邊找到了解答


textView.textContainer.lineFragmentPadding = 0; textView.textContainerInset = UIEdgeInsetsZero; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineSpacing = -0.38; NSDictionary *attrsDictionary = @{ NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:13.0f], NSParagraphStyleAttributeName: paragraphStyle}; textView.attributedText = [[NSAttributedString alloc] initWithString:textView.text attributes:attrsDictionary];