iOS 开发 00『 基础知识 』iOS Developer

iOS开发过程中遇到的一些问题 记录一下!

2016-07-28  本文已影响0人  熊猫小贼_

经常在开发过程中遇到一些奇葩的问题
这边做一个总结,记录一下开发过程中踩过的坑


1.保证列表起点的Y坐标是在 nav 下边

if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) { // 这行代码是 保证列表起点的Y坐标是在 nav 下边 () self.edgesForExtendedLayout = UIRectEdgeNone; }


2.app内跳转系统设置app相关内容
os系统中各种设置项的url链接

在代码中调用如下代码:

NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"];

[[UIApplication sharedApplication] openURL:url];

即可跳转到设置页面的对应项。

[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推送证书,用于自己搭建推送服务器的时候,跟后端匹配证书问题
具体步骤如下:

首先,需要一个pem的证书,该证书需要与开发时签名用的一致。 具体生成pem证书方法如下:

1. 登录到 iPhone Developer Connection Portal(http://developer.apple.com/iphone/manage/overview/index.action)并点击 App IDs

2. 创建一个不使用通配符的 App ID 。通配符 ID 不能用于推送通知服务。例如,  com.itotem.iphone

3. 点击App ID旁的“Configure”,然后按下按钮生产 推送通知许可证。根据“向导” 的步骤生成一个签名并上传,最后下载生成的许可证。

4. 通过双击.cer文件将你的 aps_developer_identity.cer 引入Keychain中。

5. 在Mac上启动 Keychain助手,然后在login keychain中选择 Certificates分类。你将看到一个可扩展选项“Apple Development Push Services”

6. 扩展此选项然后右击“Apple Development Push Services” > Export “Apple Development Push Services ID123”。保存为 apns-dev-cert.p12文件

7. 扩展“Apple Development Push Services” 对“Private Key”做同样操作,保存为 apns-dev-key.p12 文件。

8. 需要通过终端命令将这些文件转换为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. 如果你想要移除密码,要么在导出/转换时不要设定或者执行:

openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem

10. 最后,你需要将键和许可文件合成为apns-dev.pem文件,此文件在连接到APNS时需要使用:

cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem


4.筛选某个viewcontroller

for(UIViewController*tempVC in [self.navigationController viewControllers])

{

if([tempVC isKindOfClass:[MakeSureAddressViewController class]])

{

[tempNavBarItems removeFromParentViewController];

}

}


5.判断一个坐标点是否在一个无规则的多边形内

//    在范围内返回1,不在返回0

-(int)mutableBoundConrtolAction:(NSMutableArray *)arrSome:(CLLocationCoordinate2D )myCoordinate4{

intn=arrSome.count;

floatvertx[n];

floatverty[n];

for(inti=0; i

//MyPoint类存储的是经度和纬度

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;

}

//多边形由边界的坐标点所构成的数组组成,参数格式 该数组的count,  多边形边界点x坐标 的组成的数组,多边形边界点y坐标 的组成的数组,需要判断的点的x坐标,需要判断的点的y坐标

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 开发去除 UserInterfaceState.xcuserstate 文件为版本控制带来的困扰

原理和操作步骤见如下转载的两篇文章,

我所使用的 svn 客户端软件是 Mac 下面的 Versions.app v1.06

这个版本包含一个多人开发的bug

bug 的解决方案见我之前转载的两篇文章~

另外就是如本文转载的第一篇文章,我也深受 UserInterfaceState.xcuserstate 文件频繁更新带来的困扰,

要免除该困扰,可在 Versions 的配置文件~/.subversion/config 中忽略对 xcuserstate 类型文件的版本控制。

另外,Versions 的配置文件是处于隐藏目录的,可在 Finder 中通过 cmd + shift + g 直接跳到隐藏目录~

************************ 分割线 ***************************

文章标题:

摆脱 UserInterfaceState.xcuserstate给Xcode 版本控制(git)带来的困扰

转载自:http://alexrezit.42qu.com/10280223

今天在Xcode中Commit的时候UserInterfaceState.xcuserstate这个文件几秒钟更新一次, 搅得人不得安宁, 用.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

搞定!

************************ 分割线 ***************************

文章标题:

XCode SVN

转载自: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使用时需要配置Subversion。Leopard中自带了SVN,但Xcode的项目文件中,并不是所有文件都适于加入SVN中进 行管理,比如编译后的文件和编译过程中产生的文件,这些文件不属于源代码,应该告诉svn忽略掉,方法:编辑~/.subversion/config文 件

1.找到global-ignores一行,去掉注释,编辑成

global-ignores=build*~.nib*.so*.pbxuser*.mode*.perspective*

Xcode项目文件中有些文件是文本文件,需要告诉SVN,因为SVN能更好地管理文本文件(谁用谁知道)

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.对于 输入框为空及输入参数只有空格的判断 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);//创建要剪切的矩形框这里你可以自己修改

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)];

上一篇 下一篇

猜你喜欢

热点阅读