ในบางสถานการณ์เราอาจต้องได้ชื่อไอคอนของแอพและชื่อของภาพเริ่มต้น ตัวอย่างเช่นเมื่อแอปอยู่เบื้องหน้าจะได้รับการแจ้งเตือนระยะไกล แต่จะไม่มีการแจ้งเตือนการแจ้งเตือนในแถบการแจ้งเตือน ในเวลานี้ฉันต้องการแจ้งเตือนการแจ้งเตือนและฉันต้องใช้ชื่อไอคอน ตัวอย่างเช่นเมื่อโหลดคอนโทรลเลอร์บางตัวฉันต้องการตั้งค่าภาพพื้นหลังของคอนโทรลเลอร์เป็นภาพเริ่มต้นและฉันต้องใช้ชื่อภาพเริ่มต้น
ในความเป็นจริงภาพไอคอนถูกวางไว้ในโฟลเดอร์ Appicon System และภาพเริ่มต้นจะถูกวางไว้ในโฟลเดอร์ระบบ LaunchImage ชื่อของภาพเหล่านี้แตกต่างจากภาพทรัพยากรทั่วไปอื่น ๆ
เพื่อให้ตัวอย่างมาง่ายและหยาบกร้านกันเถอะ
สมมติว่าโครงการปัจจุบันรองรับอุปกรณ์ iPhone เท่านั้นและรองรับหน้าจอแนวตั้งเท่านั้น และไอคอน Appicon และภาพเริ่มต้นได้ถูกตั้งค่าในโครงการปัจจุบัน
จะรับชื่อไอคอนไอคอนและชื่อภาพเริ่มต้นได้อย่างไร?
บนรหัสและพิมพ์บันทึก:
/** รับไอคอนไอคอนของแอพ*/- (เป็นโมฆะ) getAppiconName {nsdictionary*infoDict = [[nsbundle mainbundle] infodictionary]; // รับชื่อไอคอนทั้งหมดในแอพ nsarray*iconsarr = infoDict [@"cfbundleicons"] [@"cfbundleprimaryicon"] [@"cfbundleiconfiles"]; // รับชื่อไอคอนสุดท้าย nsstring *iconlastname = [iconsarr lastobject]; // พิมพ์ชื่อไอคอน nslog (@"@" %@", iconlaunchName);/*บันทึกการพิมพ์: iconsarr: (Appicon29x29, Appicon40x40, Appicon60x60) iconlastname: Appicon60x60*/}/** รับชื่อภาพเริ่มต้นของแอพ *launchimagename = @""; // เริ่มต้นชื่อภาพตัวแปร cgfloat screenHeight = [uiscreen mainscreen] .bounds.size.height; // รับชื่อภาพเริ่มต้นที่ตรงกับอุปกรณ์ปัจจุบันถ้า (screenheight == 480) {// 4, 4Slaunchimagename = @"launchimage-700"; ipodlaunchimagename = @"launchimage-700-568H";} ถ้า (screenHeight == 667) {// 6, 6Slaunchimagename = @"launchimage-800-667H"; @"launchimage-800-landscape-736h";} ถ้า (launchimagename.length <1) return; // ภาพการเริ่มต้นอุปกรณ์เป็นภาพพื้นหลังของคอนโทรลเลอร์ uiimage *img = [uiimage imagenamed: launchimagename]; self.view.backgroundColor = [uicolor colorwithpatternimage: img]; -พิมพ์ข้อมูลภาพเริ่มต้นทั้งหมดที่รองรับอุปกรณ์ iPhone เท่านั้นและรองรับฉากหน้าจอแนวตั้งเท่านั้น:
/** พิมพ์ข้อมูลชื่อภาพเริ่มต้นทั้งหมดในแอพ*/- (เป็นโมฆะ) PrintAllLaunchImageInfo {nsDictionary*infoDict = [[nsbundle mainbundle] infodictionary]; // รับอาร์เรย์ข้อมูลภาพเริ่มต้นทั้งหมด nsarray *launchimagesarr = infoDict [@"uilaunchimages"]; NSLOG (@"LaunchImagesarr: %@", LaunchImagesarr); /* บันทึกการพิมพ์: ชื่อของภาพเริ่มต้นได้รับการแก้ไข launchimagesarr: ({uilaunchimageminimumosversion = "8.0"; uilaunchimagename = "launchimage-800-portrait-736h"; uilaunchimageorientation = ภาพ; uilaunchimageminimumosversion = "8.0"; "LaunchImage-800-667H"; 480} ";}, {uilaunchimageminimumosversion =" 7.0 "; uilaunchimagename =" launchimage-700-568H "; uilaunchimageorientation = ภาพบุคคล; uilaunchimagesize =" 320, 568} "; ฉันเห็นว่าไอคอน Appicon Project และข้อมูลการเริ่มต้นสามารถรับได้จาก [[NSBundle Mainbundle] Infodictionary] นอกจากนี้ยังมีข้อมูลอื่น ๆ เกี่ยวกับแอพเช่นเวอร์ชันชื่อแอพประเภทอุปกรณ์และทิศทางการสนับสนุน - -
พิมพ์ข้อมูลทั้งหมดเพื่อดู:
/** พิมพ์ข้อมูลการกำหนดค่าโครงการแอพ*/- (เป็นโมฆะ) PrintInFodictionary {NSDictionary*InfoDict = [[NSBundle Mainbundle] Infodictionary]; nslog (@"%@", infoDict); /* พิมพ์บันทึก: {buildMachineOsBuild = 15G31; CfbundledevelopmentRegion = EN; cfbundleExecutable = tantest; cfbundleicons = {cfbundlePrimaryicon = {cfbundleiconfiles = (Appicon29x29, Appicon40x40, Appicon60x60); - - cfbundleIdentifier = "net.tan.xxx"; CFBUNDLEINFODICTIONARYVERSION = "6.0"; cfbundleinfoplisturl = "info.plist - ไฟล์: ///users/px/library/developer/coresimulator/devices/7020368b-c160-42c0-b3c5-5f958fa82ef5/data/containers/bundle/application/77d8c333-a6af-4183-b79 cfbundlename = tantest; CFBUNDLENUMERICVERSION = 16809984; cfbundlepackagetype = appl; cfbundleshortversionstring = "1.0"; cfbundlesignature = "????"; cfbundlesupportedPlatforms = (iPhonesImulator); cfbundleversion = 1; dtCompiler = "com.apple.compilers.llvm.clang.1_0"; dtplatformbuild = ""; dtplatformName = iPhonesImulator; dtplatformversion = "9.3"; DTSDKBUILD = 13E230; dtsdkname = "iPhonesImulator9.3"; dtxCode = 0731; dtxCodeBuild = 7d1014; lsrequiresiphoneos = 1; minimumosversion = "6.0"; uidevicefamily = (); uilaunchimageFile = LaunchImage; uilaunchimages = ({uilaunchimageminimumosversion = "8.0"; uilaunchimagename = "Launchimage-800-portrait-736h"; uilaunchimageorientation = ภาพบุคคล; uilaunchimageize = "{414, 736}"; uilaunchimagename = "LaunchImage-800-landscape-736h"; Uilaunchimageorientation = Portrait; Uilaunchimageminimumosversion = "7.0"; uilaunchStoryboardName = LaunchScreen; uimainstoryboardfile = main; uirequiredDeviceCapabilities = (armv7); uisupportedInterfaceorientations = (uiInterfaceorientationPortrait); - --------- ถัดไปลองดูว่า Appicon และ LaunchImage เป็นอย่างไรและจะได้รับเมื่อแอพรองรับทั้งอุปกรณ์ iPhone และ iPad รวมถึงหน้าจอแนวนอนและแนวตั้ง
ก่อนอื่นให้เพิ่มสองภาพจากนั้นเพิ่มรหัสทดสอบ:
รหัสทดสอบ:
1. รับไอคอนไอคอนทั้งหมดของ Appicon
/** สนับสนุน iPhone และ iPad รับไอคอนไอคอนของแอพ */- (เป็นโมฆะ) getAppiconName {nsDictionary *infoDict = [[NSBundle Mainbundle] Infodictionary]; // รับชื่อไอคอนทั้งหมดในแอพ nsarray *iconsarr = infoDict [@"cfbundleicons"] [@"cfbundleprimaryicon"] [@"cfbundleiconfiles"]; // รับชื่อไอคอนสุดท้าย nsString *iconLastName = [iconsarr LastObject]; // พิมพ์ชื่อไอคอน nslog (@"iconsarr: %@", iconsarr); nslog (@"iconlastname: %@", iconlastname); / * ใช้บันทึกพิมพ์ (29pt และ 40pt iphone และ iPad ใช้; 60pt --- iphone, 76pt และ 83.5pt --- iPad): iconsarr: (appicon29x29, appicon40x40, appicon60x60, appicon76x76, "appicon83.5 2. รับภาพเริ่มต้นเมื่อรองรับการพัฒนา iPhone และ iPad และรองรับหน้าจอแนวนอนและแนวตั้งและตั้งค่าเป็นรหัสรูปภาพพื้นหลัง
(อุปกรณ์ iPhone มีรูปภาพเพียงสองชุดใน Plus นั่นคือ 5.5 นิ้วและอีก 4, 5 และ 6 หน้าจอแนวตั้งแบ่งปันรูปภาพเริ่มต้น)
/** สนับสนุน iPhone และ iPad รองรับหน้าจอแนวนอนและแนวตั้งรับชื่อของภาพเริ่มต้นของแอพและตั้งค่าเป็นภาพพื้นหลังของคอนโทรลเลอร์นี้*/- (เป็นโมฆะ) getLaunchimagename {nsstring*launchimagename = @""; // เริ่มต้นชื่อภาพตัวแปร cgfloat screenHeight = [uiscreen mainscreen] .bounds.size.height; // ความสูงของหน้าจอ cgfloat screenwidth = [uiscreen mainscreen] .bounds.size.width; // ความกว้างของหน้าจอ // การวางแนวอินเตอร์เฟสอุปกรณ์ uiInterfaceorientation การวางแนว = [UIAPPLICITION SharedApplication] .statusBaroRientation; BOOL ISPORTAIT = UIInterfaceOrientationIsporTrait (การวางแนว); // ไม่ว่าจะมีหน้าจอแนวตั้ง Bool Islandscape = UiInterfaceorientationislandscape (การวางแนว); // จะมีหน้าจอแนวนอน (หน้าจอแนวนอน || (IslandScape && screenWidth == 480)) {launchimagename = @"LaunchImage-700"; } // 5, 5C, 5S, หน้าจอแนวตั้ง iPod, หน้าจอแนวนอนอื่น ๆ ถ้า ((isportrait && screenHeight == 568) || (IslandScape && screenWidth == 568)) {Launchimagename = @"LaunchImage-700-568H"; } // 6, 6s หน้าจอแนวตั้ง, หน้าจอแนวนอนอื่น ๆ ถ้า ((isportrait && screenHeight == 667) || (IslandScape && screenWidth == 667)) {Launchimagename = @"LaunchImage-800-667H"; } // 6Plus, 6SPLUS หน้าจอแนวตั้งอื่น ๆ ถ้า (isPortrait && screenHeight == 736) {LaunchImagename = @"LaunchImage-800-portrait-736h"; } // 6Plus, 6SPLUS หน้าจอแนวนอนอื่น ๆ ถ้า (IslandScape && screenWidth == 736) {launchimagename = @"LaunchImage-800-Landscape-736h"; } // หน้าจอแนวตั้ง iPad อื่นถ้า (isPortrait && screenHeight == 1024) {launchimagename = @"launchimage-700-portrait"; } // หน้าจอแนวนอน iPad อื่นถ้า (IslandScape && screenWidth == 1024) {launchimagename = @"LaunchImage-700-Landscape"; } if (launchimagename.length <1) return; // ภาพเริ่มต้นอุปกรณ์เป็นภาพพื้นหลังของคอนโทรลเลอร์ uiimage *img = [uiimage imagenamed: launchimagename]; self.view.backgroundColor = [uicolor colorwithpatternimage: img];}3. พิมพ์ข้อมูลภาพเริ่มต้นทั้งหมด
/** พิมพ์ข้อมูลชื่อภาพเริ่มต้นทั้งหมดในแอพ*/- (เป็นโมฆะ) PrintAllLaunchImageInfo {nsDictionary*infoDict = [[nsbundle mainbundle] infodictionary]; // รับอาร์เรย์ข้อมูลภาพเริ่มต้นทั้งหมด nsarray *launchimagesarr = infoDict [@"uilaunchimages"]; NSLOG (@"LaunchImagesarr: %@", LaunchImagesarr); /* บันทึกการพิมพ์: ชื่อของภาพเริ่มต้นได้รับการแก้ไข launchimagesarr: ({uilaunchimageminimumosversion = "8.0"; uilaunchimagename = "launchimage-800-portrait-736h"; uilaunchimageorientation = ภาพ; uilaunchimageminimumosversion = "8.0"; "LaunchImage-800-667H"; 480} ";}, {uilaunchimageminimumosversion =" 7.0 "; uilaunchimagename =" launchimage-700-568H "; uilaunchimageorientation = Portrait; uilaunchimagesize =" {320, 568} "; uilaunchimagename = "LaunchImage-700-portrait"; uilaunchimagesize = "{768, 1024}"; }, {uilaunchimageminimumosversion = "7.0"; uilaunchimagename = "launchimage-700-landscape"; UilaunchimageOrientation = ภูมิทัศน์; uilaunchimagesize = "{768, 1024}"; - 4. พิมพ์ข้อมูลการกำหนดค่าทั้งหมด
/** พิมพ์ข้อมูลการกำหนดค่าโครงการแอพ*/- (เป็นโมฆะ) PrintInFodictionary {NSDictionary*InfoDict = [[NSBundle Mainbundle] Infodictionary]; nslog (@"%@", infoDict); /* พิมพ์บันทึก: {buildMachineOsBuild = 15G31; CfbundledevelopmentRegion = EN; cfbundleExecutable = tantest; cfbundleicons = {cfbundlePrimaryicon = {cfbundleiconfiles = (Appicon29x29, Appicon40x40, Appicon60x60, Appicon76x76, "Appicon83.5x83.5"); - - cfbundleIdentifier = "net.tan.xxx"; CFBUNDLEINFODICTIONARYVERSION = "6.0"; cfbundleinfoplisturl = "info.plist - ไฟล์: /// ผู้ใช้/px/ไลบรารี/นักพัฒนา/coresimulator/อุปกรณ์/3246F9AE-1D73-4E4F-8DDF-F591DBE64 f63/data/containers/bundle/application/7dd6c793-f882-43cf-9897-1433411289E6/tantest.app/"; cfbundlename = tantest; CFBUNDLENUMERICVERSION = 16809984; cfbundlepackagetype = appl; cfbundleshortversionstring = "1.0"; cfbundlesignature = "????"; cfbundlesupportedPlatforms = (iPhonesImulator); cfbundleversion = 1; dtCompiler = "com.apple.compilers.llvm.clang.1_0"; dtplatformbuild = ""; dtplatformName = iPhonesImulator; dtplatformversion = "9.3"; DTSDKBUILD = 13E230; dtsdkname = "iPhonesImulator9.3"; dtxCode = 0731; dtxCodeBuild = 7d1014; lsrequiresiphoneos = 1; minimumosversion = "9.0"; uidevicefamily = (1,); uilaunchimageFile = LaunchImage; uilaunchimages = ({uilaunchimageminimumosversion = "8.0"; uilaunchimagename = "Launchimage-800-portrait-736h"; uilaunchimageorientation = portrait; uilaunchimageize = "{414, 736}"; uilaunchimagename = "LaunchImage-800-landscape-736h"; Uilaunchimageorientation = Portrait; uilaunchimageminimumosversion = "7.0"; "LaunchImage-700-portrait"; uilaunchimagename = "launchimage-700-landscape"; UilaunchimageOrientation = ภูมิทัศน์; uilaunchimagesize = "{768, 1024}"; - uilaunchStoryboardName = LaunchScreen; uimainstoryboardfile = main; uirequiredDeviceCapabilities = (armv7); UIsupportedInterfaceorientations = (uiInterfaceorientationPortrait, uiinterfaceorientationlandscapelef, uiinterfaceorientationlandscaperight); -ด้านบนเป็นชื่อของ iOS Appicon และ LaunchImage (ไอคอนแอพและชื่อภาพเรียกใช้) แนะนำโดยบรรณาธิการ ฉันหวังว่ามันจะเป็นประโยชน์กับทุกคน หากคุณมีคำถามใด ๆ โปรดฝากข้อความถึงฉันและบรรณาธิการจะตอบกลับทุกคนในเวลา ขอบคุณมากสำหรับการสนับสนุนเว็บไซต์ Wulin.com!