經(jīng)常在開發(fā)過程中遇到一些奇葩的問題
這邊做一個(gè)總結(jié),記錄一下開發(fā)過程中踩過的坑
1.保證列表起點(diǎn)的Y坐標(biāo)是在 nav 下邊
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) { // 這行代碼是 保證列表起點(diǎn)的Y坐標(biāo)是在 nav 下邊 () self.edgesForExtendedLayout = UIRectEdgeNone; }
2.app內(nèi)跳轉(zhuǎn)系統(tǒng)設(shè)置app相關(guān)內(nèi)容
os系統(tǒng)中各種設(shè)置項(xiàng)的url鏈接
在代碼中調(diào)用如下代碼:
NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"];
[[UIApplication sharedApplication] openURL:url];
即可跳轉(zhuǎn)到設(shè)置頁面的對應(yīng)項(xiàng)。
[font=]
About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
Airplane Mode On — prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date & Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General — prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE
iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari
Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI
prefs:root=INTERNET_TETHERING
3.iOS_生成pem推送證書,用于自己搭建推送服務(wù)器的時(shí)候,跟后端匹配證書問題
具體步驟如下:
首先,需要一個(gè)pem的證書,該證書需要與開發(fā)時(shí)簽名用的一致。 具體生成pem證書方法如下:
1. 登錄到 iPhone Developer Connection Portal(http://developer.apple.com/iphone/manage/overview/index.action)并點(diǎn)擊 App IDs
2. 創(chuàng)建一個(gè)不使用通配符的 App ID 。通配符 ID 不能用于推送通知服務(wù)。例如,??com.itotem.iphone
3. 點(diǎn)擊App ID旁的“Configure”,然后按下按鈕生產(chǎn) 推送通知許可證。根據(jù)“向?qū)А?的步驟生成一個(gè)簽名并上傳,最后下載生成的許可證。
4. 通過雙擊.cer文件將你的 aps_developer_identity.cer 引入Keychain中。
5. 在Mac上啟動 Keychain助手,然后在login keychain中選擇 Certificates分類。你將看到一個(gè)可擴(kuò)展選項(xiàng)“Apple Development Push Services”
6. 擴(kuò)展此選項(xiàng)然后右擊“Apple Development Push Services” > Export “Apple Development Push Services ID123”。保存為 apns-dev-cert.p12文件。
7. 擴(kuò)展“Apple Development Push Services” 對“Private Key”做同樣操作,保存為 apns-dev-key.p12 文件。
8. 需要通過終端命令將這些文件轉(zhuǎn)換為PEM格式:openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12
openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12
9. 如果你想要移除密碼,要么在導(dǎo)出/轉(zhuǎn)換時(shí)不要設(shè)定或者執(zhí)行:
openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem
10. 最后,你需要將鍵和許可文件合成為apns-dev.pem文件,此文件在連接到APNS時(shí)需要使用:
cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem
4.篩選某個(gè)viewcontroller
for(UIViewController*tempVC in [self.navigationController viewControllers])
{
if([tempVC isKindOfClass:[MakeSureAddressViewController class]])
{
[tempNavBarItems removeFromParentViewController];
}
}
5.判斷一個(gè)坐標(biāo)點(diǎn)是否在一個(gè)無規(guī)則的多邊形內(nèi)
//????在范圍內(nèi)返回1,不在返回0
-(int)mutableBoundConrtolAction:(NSMutableArray?*)arrSome:(CLLocationCoordinate2D?)myCoordinate4{
intn=arrSome.count;
floatvertx[n];
floatverty[n];
for(inti=0;?i
//MyPoint類存儲的是經(jīng)度和緯度
vertx[i]=((MyPoint?*)(arrSome[i])).x;
verty[i]=((MyPoint?*)(arrSome[i])).y;
}
if(arrSome.count==0)?{
return1;
}
BOOLi=pnpoly(arrSome.count,?vertx,?verty,?myCoordinate4.latitude,?myCoordinate4.longitude);
if(i)?{
return1;
}else{
return0;
}
return1;
}
//多邊形由邊界的坐標(biāo)點(diǎn)所構(gòu)成的數(shù)組組成,參數(shù)格式?該數(shù)組的count,??多邊形邊界點(diǎn)x坐標(biāo)?的組成的數(shù)組,多邊形邊界點(diǎn)y坐標(biāo)?的組成的數(shù)組,需要判斷的點(diǎn)的x坐標(biāo),需要判斷的點(diǎn)的y坐標(biāo)
BOOLpnpoly?(intnvert,float*vertx,float*verty,floattestx,floattesty)?{
inti,?j;
BOOLc=NO;
for(i?=?0,?j?=?nvert-1;?i?<?nvert;?j?=?i++)?{
if(?(?(verty[i]>testy)?!=?(verty[j]>testy)?)?&&
(testx?<?(vertx[j]-vertx[i])?*?(testy-verty[i])?/?(verty[j]-verty[i])?+?vertx[i])?)
c?=?!c;
}
returnc;
}
6.XCode 開發(fā)去除 UserInterfaceState.xcuserstate 文件為版本控制帶來的困擾
原理和操作步驟見如下轉(zhuǎn)載的兩篇文章,
我所使用的 svn 客戶端軟件是 Mac 下面的 Versions.app v1.06
這個(gè)版本包含一個(gè)多人開發(fā)的bug
bug 的解決方案見我之前轉(zhuǎn)載的兩篇文章~
另外就是如本文轉(zhuǎn)載的第一篇文章,我也深受 UserInterfaceState.xcuserstate 文件頻繁更新帶來的困擾,
要免除該困擾,可在 Versions 的配置文件~/.subversion/config 中忽略對 xcuserstate 類型文件的版本控制。
另外,Versions 的配置文件是處于隱藏目錄的,可在 Finder 中通過 cmd + shift + g 直接跳到隱藏目錄~
************************ 分割線 ***************************
文章標(biāo)題:
擺脫 UserInterfaceState.xcuserstate給Xcode 版本控制(git)帶來的困擾
轉(zhuǎn)載自:http://alexrezit.42qu.com/10280223
今天在Xcode中Commit的時(shí)候UserInterfaceState.xcuserstate這個(gè)文件幾秒鐘更新一次, 攪得人不得安寧, 用.gitignore無效. 于是, 在終端中輸入:
$ git rm --cached iLedger.xcodeproj/project.xcworkspace/xcuserdata/Alex.xcuserdatad/UserInterfaceState.xcuserstate
$ git commit -m "Removed the stupid strange file that shouldn't be tracked"
$ git push
搞定!
************************ 分割線 ***************************
文章標(biāo)題:
XCode SVN
轉(zhuǎn)載自:http://renxiangzyq.iteye.com/blog/850762
Create the project in XCODE.
Setup subversion in XCODE and select the subversion repository for this project.
Use Xcode SCM > Repository and click on the IMPORT icon. This will move the local copy to the subversion repository.
Now delete your local copy (or move it to another location just in case).
Finally CHECKOUT the project from subversion (this will create the subversion .svn folders, …).
Reselect the subversion repository for this project.
Commit the entire project.
第一步,配置Subversion
Xcode中SVN使用時(shí)需要配置Subversion。Leopard中自帶了SVN,但Xcode的項(xiàng)目文件中,并不是所有文件都適于加入SVN中進(jìn) 行管理,比如編譯后的文件和編譯過程中產(chǎn)生的文件,這些文件不屬于源代碼,應(yīng)該告訴svn忽略掉,方法:編輯~/.subversion/config文 件
1.找到global-ignores一行,去掉注釋,編輯成
global-ignores=build*~.nib*.so*.pbxuser*.mode*.perspective*
Xcode項(xiàng)目文件中有些文件是文本文件,需要告訴SVN,因?yàn)镾VN能更好地管理文本文件(誰用誰知道)
2.找到enable-auto-props=yes把注釋去掉,在[auto-props]Section聲明以下文本文件
*.mode*=svn:mime-type=text/X-xcode
*.pbxuser=svn:mime-type=text/X-xcode
*.perspective*=svn:mime-type=text/X-xcode
*.pbxproj=svn:mime-type=text/X-xcode
7.對于 輸入框?yàn)榭占拜斎雲(yún)?shù)只有空格的判斷 ios
-(Bool) isEmpty:(NSString*) str {
if(!str) {
returntrue;
}else{
//A character set containing only the whitespace characters space (U+0020) and tab (U+0009) and the newline and nextline characters (U+000A–U+000D, U+0085).
NSCharacterSet*set =[NSCharacterSetwhitespaceAndNewlineCharacterSet];
//Returns a new string made by removing from both ends of the receiver characters contained in a given character set.
NSString*trimedString = [strstringByTrimmingCharactersInSet:set];
if([trimedStringlength] ==0) {
returntrue;
}else{
returnfalse;
}
}
}
8.ios-->截圖、生成指定大小圖片以及壓縮
1、截圖
UIImage*snapshot;
CGImageRefcgScreen=UIGetScreenImage();
if(cgScreen){
snapshot=[UIImageimageWithCGImage:cgScreen];
CGImageRelease(cgScreen);
}
CGRectrect=CGRectMake(0,125,640,750);//創(chuàng)建要剪切的矩形框這里你可以自己修改
UIImage*res=[UIImageimageWithCGImage:CGImageCreateWithImageInRect([snapshotCGImage],rect)]
//res就是截圖后的UIImage
2、生成指定大小圖片
+ (UIImage *)compressImage:(UIImage *)imgSrc
{
CGSize size = {320, 480};
UIGraphicsBeginImageContext(size);
CGRect rect = {{0,0}, size};
[imgSrc drawInRect:rect];
UIImage *compressedImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return compressedImg;
}
3、壓縮
UIImage *img = [CImageUtil compressImage:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];
NSData *imageData = [[NSData alloc] initWithData:UIImageJPEGRepresentation(img, 0.1)];