iOS development--adapted to iOS 10 and Xcode 8

http://www.cocoachina.com/ios/20161014/17574.html

 

As far as my use is concerned, I feel that Apple is still in constant pits, but it is also making progress. Let me talk about the adaptation of iOS10 and some points of attention in the use of Xcode8.

1. Certificate Management

After opening the project with Xcode8, the following picture is more obvious. This is a new feature of Apple that can help us manage certificates automatically. It is recommended that you check this Automatically manage signing (Ps. But when I used the beat2 version, it was completely impossible. The GM version was amazing and good.)

01.png

Here's my list of possible problems:

1. A screenshot of Xcode without setting up a developer account

02.png

The solution is: you can add an Apple account in the preferences of Xcode.

2. Screenshots when the device machine is not added to the developer's Device

03.png

The solution is: after you add the device to the development machine on the official website, you can accompany the description file and re-create the next description file.

3. Normal situation: Xcode configures the picture after logging in to the developer account, just wait patiently.

04.png

Picture after waiting

05.png

2. Notes on Xib files

After opening the xib file with Xcode8, the prompt shown below will appear.

06.png

You can choose Choose Device.
After that, you will find that the layout is messed up, and you only need to update the frame. As shown below

07.png

Note: If you follow the above steps, an error will be reported when you open Xib with Xcode7,

08.png

Solution: need to delete Xib inside

4.png

This sentence, as well as changing 5.pngthe toolsVersion in and 6.pngversion in your normal xib file to the value in your normal xib file
, but this is not recommended. After Xcode8 comes out, I hope everyone can get started quickly and update all staff. This is the same as Xcode5 to Xcode6, there are changes, but you still have to learn and adapt as soon as possible!

Three, code and API attention

使用Xcode8之后,有些代码可能就编译不过去了,具体我就说说我碰到的问题。
1.UIWebView的代理方法:
**注意要删除NSError前面的 nullable,否则报错。

1
2
3
4
- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error
{
     [self hideHud];
}

四、代码注释不能用的解决办法

这个是因为苹果解决xcode ghost,把插件屏蔽了。
解决方法
打开终端,命令运行:  sudo /usr/libexec/xpccachectl
然后必须重启电脑后生效

注意:Xcode8内置了开启注释的功能,位置在这里

707724-9ace6550ccedaa6c.png

快捷键的设置在这里

707724-ed9730ab858c08a7.png

貌似Xcode8取消了三方插件的功能,具体可以查阅下Xcode8 Source Editor

五、权限以及相关设置

注意,添加的时候,末尾不要有空格
我们需要打开info.plist文件添加相应权限的说明,否则程序在iOS10上会出现崩溃。
具体如下图:

707724-d118ca12029c78ab.png

麦克风权限:Privacy - Microphone Usage Description 是否允许此App使用你的麦克风?
相机权限: Privacy - Camera Usage Description 是否允许此App使用你的相机?
相册权限: Privacy - Photo Library Usage Description 是否允许此App访问你的媒体资料库?通讯录权限: Privacy - Contacts Usage Description 是否允许此App访问你的通讯录?
蓝牙权限:Privacy - Bluetooth Peripheral Usage Description 是否许允此App使用蓝牙?

语音转文字权限:Privacy - Speech Recognition Usage Description 是否允许此App使用语音识别?
日历权限:Privacy - Calendars Usage Description 是否允许此App使用日历?

定位权限:Privacy - Location When In Use Usage Description 我们需要通过您的地理位置信息获取您周边的相关数据
定位权限: Privacy - Location Always Usage Description 我们需要通过您的地理位置信息获取您周边的相关数据
定位的需要这么写,防止上架被拒。

六、字体变大,原有frame需要适配

经有的朋友提醒,发现程序内原来2个字的宽度是24,现在2个字需要27的宽度来显示了。。
希望有解决办法的朋友,评论告我一下耶,谢谢啦

七、推送

如下图的部分,不要忘记打开。所有的推送平台,不管是极光还是什么的,要想收到推送,这个是必须打开的哟??

11.png

之后就应该可以收到推送了。另外,极光推送也推出新版本了,大家也可以更新下。

PS.苹果这次对推送做了很大的变化,希望大家多查阅查阅,处理推送的代理方法也变化了。

4.png

iOS10收到通知不再是在
[application: didReceiveRemoteNotification:]方法去处理, iOS10推出新的代理方法,接收和处理各类通知(本地或者远程)

1
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {  //应用在前台收到通知 NSLog(@"========%@", notification);}- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler { //点击通知进入应用 NSLog(@"response:%@", response);}

稍后我会更新文章,对推送做一个详细的讲解。

8.屏蔽杂乱无章的bug

更新Xcode8之后,新建立工程,都会打印一堆莫名其妙看不懂的Log.
如这些

1
subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1,

The method of shielding is as follows:
Edit Scheme-> Run -> Arguments in Xcode8, add
OS_ACTIVITY_MODE = Disable in Environment Variables

36.png

If the log is still printed after writing, please re-check the checkmark, it can be solved.

Ps. Considering that after adding the above content in Xcode8, the real machine debugging may be abnormal, you can customize a macro definition for log output.

1
2
3
4
5
6
7
8
9
10
11
#ifdef DEBUG
 
#define DDLOG(...) printf(" %s\n",[[NSString stringWithFormat:__VA_ARGS__]UTF8String]);
#define DDLOG_CURRENT_METHOD NSLog(@"%@-%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd))
 
#else
 
#define DDLOG(...) ;
#define DDLOG_CURRENT_METHOD ;
 
#endif

If you have any questions, you can comment to me~
If the writing is good, I hope you can follow me. grateful.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326488913&siteId=291194637