[iOS]适配iPhone X的几件事

2017年12月23日 iOS 10条评论 阅读5762次

[iOS]适配iPhone X的几件事

前两天收到用户反映说有在iPhone X手机上,APP发生闪退的情况。
针对此问题,大体回想了上次打包发布时的过程,应该是已经适配iOS11了,并且在线监控用户日志,也确实有最近不少iOS11的设备在使用。
自己没有iPhone X的手机,身边同事也没有,想到先用模拟器测试一下,启动模拟器一运行,果然好没留情地出现了闪退。能重现的bug就好解决,查看一下控制台日志。


2017-12-21 15:56:39.907695+0800 JILENIAO[82637:9080591] -[LoginViewController viewDidLoad] Line:33 
 viewDidLoad
2017-12-21 15:56:39.928810+0800 JILENIAO[82637:9080591] [MC] Lazy loading NSBundle MobileCoreServices.framework
2017-12-21 15:56:39.930377+0800 JILENIAO[82637:9080591] [MC] Loaded MobileCoreServices.framework
2017-12-21 15:56:39.989425+0800 JILENIAO[82637:9080591] -[LoginViewController viewDidAppear:] Line:63 
 viewDidAppear
2017-12-21 15:56:40.007140+0800 JILENIAO[82637:9080591] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIStatusBar_Modern 0x7fe2f4508280> valueForUndefinedKey:]: this class is not key value coding-compliant for the key foregroundView.'
*** First throw call stack:
(
 0   CoreFoundation                      0x000000011077912b __exceptionPreprocess + 171
 1   libobjc.A.dylib                     0x000000011166bf41 objc_exception_throw + 48
 2   CoreFoundation                      0x0000000110779079 -[NSException raise] + 9
 3   Foundation                          0x000000010fa5d9ae -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 226
 4   Foundation                          0x000000010f988d80 -[NSObject(NSKeyValueCoding) valueForKey:] + 284
 5   JILENIAO                            0x000000010cf008fd +[NetworkUtil getNetworkAccess] + 173
 6   JILENIAO                            0x000000010cef48da -[LoginViewController viewDidAppear:] + 186
 7   UIKit                               0x000000010d7de24f -[UIViewController _setViewAppearState:isAnimating:] + 699
 8   UIKit                               0x000000010d7e10f9 __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke + 42
 9   UIKit                               0x000000010d7df3ed -[UIViewController _executeAfterAppearanceBlock] + 86
 10  UIKit                               0x000000010d63be95 _runAfterCACommitDeferredBlocks + 634
 11  UIKit                               0x000000010d62abb1 _cleanUpAfterCAFlushAndRunDeferredBlocks + 280
 12  UIKit                               0x000000010d64b278 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 155
 13  CoreFoundation                      0x000000011071c05c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
 14  CoreFoundation                      0x000000011070083b __CFRunLoopDoBlocks + 203
 15  CoreFoundation                      0x0000000110700014 __CFRunLoopRun + 1300
 16  CoreFoundation                      0x00000001106ff889 CFRunLoopRunSpecific + 409
 17  GraphicsServices                    0x00000001136c39c6 GSEventRunModal + 62
 18  UIKit                               0x000000010d6305d6 UIApplicationMain + 159
 19  JILENIAO                            0x000000010cf2cb6f main + 111
 20  libdyld.dylib                       0x000000011237ad81 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 


有了这个信息,错误就很明显了,具体调用的方法名行数都出来了,并且还有炫富性质的UIStatusBar_Modern状态栏字样,让我足够有信息知道这个iPhone X的状态栏上的问题。

之前在判断网络类型时,用了获取设备状态栏信息的方法,也就是下面的一行代码。


UIApplication *app = [UIApplication sharedApplication];
NSArray *children = [[[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"foregroundView"]subviews];
for (id child in children) {
    ...
}


断点打在这里,使用po查看app中信息,发现的确是状态栏内View的包装方式发生了变化。组织新的获取方式。


if ([[app valueForKeyPath:@"_statusBar"] isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {
    children = [[[[app valueForKeyPath:@"_statusBar"] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
} else {
    children = [[[app valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
}


顺便把之前适配iPhone X时的注意点也发出来吧。

iOS-adapt-iPhoneX.jpeg


iPhone X的启动图片大小分辨率

iPhone X的启动图分辨率必须是是1125px × 2436px

至于iPhone X的启动图片的命名,因为没找到官方说明,参照网上前辈的做法,将iPhone X的启动图片命名为 LaunchImage-Default-iOS11-812h@3x.png

iPhone X的启动图片设置需要右侧Launch Image下勾选iOS8.0 and later


APP中集成了极光推送,在AppDelegate#application:didReceiveRemoteNotification:fetchCompletionHandler:方法中加入了接收到远程通知的逻辑,所以需要如下操作:


Xcode -> Targets -> Capabilities -> Background Modes (勾选打开) -> Remote notifications (勾选打开) && Background Fetch (勾选打开) 



上述操作之前错误如下:


2017-12-21 16:39:36.705300+0800 JILENIAO[83460:9151112] You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.


iPhone X刘海状态栏高度适配

之前很多地方用到屏幕状态栏高度时,都是写成固定数20,虽然历经多少年多少代iPhone的发布这个固定数并没带来页面适配问题,但天生带有刘海的iPhone X就不一样了。



iPhone X的状态栏高度是44,已经不是20了。
当然我们不能判断是否是iPhone X来写44或20了,系统提供了很简单的方法来获取状态栏高度

CGFloat statusBarHeight = CGRectGetHeight([UIApplication sharedApplication].statusBarFrame);





分享本文至:

WRITTEN BY

avatar
本文标签:iOSiPhoneX
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

10 条评论

  1. avatar mylinkstv

    <a href="http://www.evolutionecig.com/nike-hyperdunk-2016-low-hommes-vert-runninge">nike hyperdunk 2016 low hommes vert</a> <a href="http://www.georginabauer.com/nike-huarache-femmes-violet-schuhea">nike huarache femmes violet</a> <a href="http://www.bootsoffprice.com/air-jordan-retro-3-kvinders-gr%C3%A5-hvid-scarpeb">air jordan retro 3 kvinders gr氓 hvid</a> <a href="http://www.theprintjobs.com/nike-air-max-95-green-spain-shoeso">nike air max 95 green spain</a> <a href="http://www.dbajournal.com/air-max-1-hyperfuse-marinen-kurpesc">air max 1 hyperfuse marinen</a> <a href="http://www.procomedian.com/womens-nike-shox-navina-sparkle-black-zapatost">womens nike shox navina sparkle black</a>
    mylinkstv http://www.mylinkstv.com/

  2. avatar ladivorcecpa

    <a href="http://www.perlai.com/hommes-nike-air-max-bw-or-violet-scarpea">hommes nike air max bw or violet</a> <a href="http://www.robotultra.com/kobe-9-victory-for-salg-schuheb">kobe 9 victory for salg</a> <a href="http://www.sphygmic.com/nike-zoom-winflo-3-kvinders-gr%C3%B8n-sort-butye">nike zoom winflo 3 kvinders gr酶n sort</a> <a href="http://www.swellvelo.com/nike-air-max-1-daring-rojo-butye">nike air max 1 daring rojo</a> <a href="http://www.angguvenlik.com/air-jordan-1-retro-og-for-venta-obuvf">air jordan 1 retro og for venta</a> <a href="http://www.boigemenskap.com/flyknit-air-max-infrar%C3%B8d-kit-obuvd">flyknit air max infrar酶d kit</a>
    ladivorcecpa http://www.ladivorcecpa.com/

  3. avatar sdsremote

    <a href="http://www.sfhires.com/burberry-tie-price-tier">burberry tie price</a> <a href="http://www.myenergytruth.com/burberry-personalized-scarf-scarfr">burberry personalized scarf</a> <a href="http://www.klarinettino.com/nobis-merideth-xs-nobisr">nobis merideth xs</a> <a href="http://www.printonlypros.com/air-jordan-4-retro-fire-red-white-black-cement-grey-red-trainersa">air jordan 4 retro fire red white black cement grey red</a> <a href="http://www.ralfwentz.com/hermes-red-enamel-clic-h-bracelet-narrow-width-18mm-in-gold-jewelryr">hermes red enamel clic h bracelet narrow width 18mm in gold</a> <a href="http://www.hotelsuixlara.com/bon-march%C3%A9-nike-free-4.0-femmes-argent-sneakerf">bon march茅 nike free 4.0 femmes argent</a>
    sdsremote http://www.sdsremote.com/

  4. avatar calvarynola

    <a href="http://www.mipaneldecontrol.net/nike-roshe-run-br-trainers-schwarz-schuhea">nike roshe run br trainers schwarz</a> <a href="http://www.moombaki.net/nike-foamposite-yeezy-for-venta-mn-kurpesb">nike foamposite yeezy for venta mn</a> <a href="http://www.mtcsolutions.net/air-jordan-14-gituttio-arancia-schuhef">air jordan 14 gituttio arancia</a> <a href="http://www.muftimuneer.net/air-jordan-1-anodized-gr%C3%B8nn-butye">air jordan 1 anodized gr酶nn</a> <a href="http://www.mypotatocrop.net/nike-zoom-clear-out-2-hvid-orange-obuvd">nike zoom clear out 2 hvid orange</a> <a href="http://www.nicholasbasbanes.net/nike-maschio-air-max-90-fashion-sneaker-scarpee">nike maschio air max 90 fashion sneaker</a>
    calvarynola http://www.calvarynola.net/

  5. avatar ozoessaouira

    <a href="http://www.kainjipark.com/lebron-witness-ii-mens-basketball-shoe-zapatost">lebron witness ii mens basketball shoe</a> <a href="http://www.lapthelakes.com/girls-high-converse-shoesz">girls high converse</a> <a href="http://www.delmaroffice.com/air-jordan-retro-11-alle-r%C3%B8d-schuheb">air jordan retro 11 alle r酶d</a> <a href="http://www.medieneinsatz.com/limited-nike-brown-youth-chad-thomas-home-jersey-nfl-92-cleveland-browns-vapor-untouchable-nflu">limited nike brown youth chad thomas home jersey nfl 92 cleveland browns vapor untouchable</a> <a href="http://www.linexcanton.com/buy-nike-air-max-1-black-skou">buy nike air max 1 black</a> <a href="http://www.saskostomy.com/nike-huarache-khaki-ingredients-runningf">nike huarache khaki ingredients</a>
    ozoessaouira http://www.ozoessaouira.com/

  6. avatar singingtoons

    <a href="http://www.hitsturbines.com/nfl-marqise-lee-womens-gold-11-jacksonville-jaguars-nike-rush-pride-name-number-t-shirt-nflr">nfl marqise lee womens gold 11 jacksonville jaguars nike rush pride name number t shirt</a> <a href="http://www.jadamsrealtor.com/mens-nike-new-york-giants-53-harry-carson-limited-red-rush-drift-fashion-nfl-jersey-nflw">mens nike new york giants 53 harry carson limited red rush drift fashion nfl jersey</a> <a href="http://www.karenconti.com/salomon-s-lab-fellcross-2-sort-line-schuhef">salomon s lab fellcross 2 sort line</a> <a href="http://www.cliffsears.com/nike-foamposite-yeezy-for-salg-used-scarpeg">nike foamposite yeezy for salg used</a> <a href="http://www.rfsloan.com/dam%C3%A4nner-nike-roshe-run-triangle-wei%C3%9F-rot-kurpesf">dam盲nner nike roshe run triangle wei脽 rot</a> <a href="http://www.gfwholesalers.com/nike-zoom-todas-out-negro-no-flocking-schuheg">nike zoom todas out negro no flocking</a>
    singingtoons http://www.singingtoons.com/

  7. avatar hookupwithher

    <a href="http://www.royalhoneywax.com/spot-fake-ferragamo-belt-beltr">spot fake ferragamo belt</a> <a href="http://www.carslambert.com/oakley-forsake-sunglasses-white-sunglassesd">oakley forsake sunglasses white</a> <a href="http://www.hiussalipiilo.com/nike-hat-white-blank-mens-black-hatg">nike hat white blank mens black</a> <a href="http://www.hospicevna.com/ray-ban-wayfarer-qb2457-user-manual-sunglassese">ray ban wayfarer qb2457 user manual</a> <a href="http://www.smartpaul.com/nike-internationalist-herren-schwarz-wei%C3%9F-skox">nike internationalist herren schwarz wei脽</a> <a href="http://www.opendekalbinc.com/air-jordan-14-black-toe-for-sale-georgia-skoc">air jordan 14 black toe for sale georgia</a>
    [url=http://www.hookupwithher.com/]hookupwithher[/url]

  8. avatar cockaweek

    <a href="http://www.alfiekaye.com/mulberry-classic-bayswater-bag-mulberryr">mulberry classic bayswater bag</a> <a href="http://www.lateraline.com/mlb-jerseys-chicago-white-sox-45-michael-jordan-white-jerseys-nflv">mlb jerseys chicago white sox 45 michael jordan white jerseys</a> <a href="http://www.primumlive.com/%EF%BB%BFparajumpers-gobi-jacket-parajumpersr">锘縫arajumpers gobi jacket</a> <a href="http://www.fonepsi.com/burberry-london-silk-tie-tier">burberry london silk tie</a> <a href="http://www.kainstory.com/moncler-tech-puffer-jacket-monclerr">moncler tech puffer jacket</a> <a href="http://www.dandrehobl.com/prada-brown-leather-handbag-pradar">prada brown leather handbag</a>
    cockaweek http://www.cockaweek.com/

  9. avatar 大香蕉

    学习一下,上次打包一个花了N多天没搞定。

  10. avatar JIUCAIJIUCAI

    好好学习下

欢迎留言




用户登录

sitemap