[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$fZbUNnQAPV55TN9l3GSiULVwFQroYZ65QZuMoyDn1UI8":3},{"code":4,"message":5,"data":6},200,"成功",{"id":7,"createdAt":8,"title":9,"content":10,"summary":11,"image":12,"uid":13,"user":14,"categoryId":21,"category":22,"subCategoryId":24,"subCategory":25,"comments":27,"status":17,"reason":28,"notice":28,"visitCount":29,"commentCount":30,"keywords":31},151,"2025-02-25T10:02:54.466Z","ITMS-90683: Missing purpose string in info.plist. NSAppleMusicUsageDescription - flutter - permission_handler","## 背景\n在开发flutter的过程中没有出现异常，但是在提交iOS app到审核的时候，出现了报错，提示缺少在info.plist中的权限描述。问题如下截图所示：\n\n![ITMS-90683 issue](https://image.xinwei.ltd/20250225-0427501740475825483.jpeg)\n\n> ITMS-90683: Missing purpose string in info.plist\n\n\n## 问题分析\n从截图中可以看出，Apple提示我的iOS工程中缺少`NSAppleMusicUsageDescription`和`NSLocationAlwaysWhenInUseUsageDescription`这2个权限的描述。\n\n开发过iOS的小伙伴肯定知道，如果我们在代码中有对隐私权限的调用（相册、相机、定位、麦克风、电话簿等），如果没有在主target中的info.plist添加目的描述，Apple是不允许的，并且Apple还会让开发者在appconnect提审网站上对app使用到的一些隐私、加密等内容做勾选。\n\n如果是在iOS纯原生代码开发中，我们是比较快的定位问题的，但是在flutter开发的时候，由于有时候加的flutter package太多，导致我们容易遗忘有哪些权限描述需要及时在info.plist中进行填写，纯属是一个细心问题。\n\n这样的问题，我也在网上找到过有人也犯过同样的错误：[https://github.com/Baseflow/flutter-permission-handler/issues/302](https://github.com/Baseflow/flutter-permission-handler/issues/302)\n\n## 问题解决\n在flutter中，我们通常使用`permission_handler`这个库来检查和请求业务功能所需的权限。\n\n说到这个库，有一个问题需要提到，就是，如果有同学没有按照文档的`ios setup`部分将iOS工程进行配置的话，会出现`权限虽然获取到了，但是check权限状态时却是foreverDenied`的问题。\n![permission-handler ios setup](https://image.xinwei.ltd/image1740477251312.png)\n\n\n这个问题一定要切记。\n\n`permission-handler`这个pub的链接是：[https://pub.dev/packages/permission_handler](https://pub.dev/packages/permission_handler)\n\n那么，当你使用flutter开发的时候，如果是遇到类似`Missing purpose string in info.plist`这样的报错，你就应该首先检查`permission_handler`这个库的配置是否正确。\n\n其中最不容易发现的是，问题不在代码，而是在`Podfile`文件中，我这里贴出我的`Podfile`文件，供大家参考：\n```Podfile\n# Uncomment this line to define a global platform for your project\nplatform :ios, '13.0'\n\n# CocoaPods analytics sends network stats synchronously affecting flutter build latency.\nENV['COCOAPODS_DISABLE_STATS'] = 'true'\n\nproject 'Runner', {\n  'Debug' => :debug,\n  'Profile' => :release,\n  'Release' => :release,\n}\n\ndef flutter_root\n  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)\n  unless File.exist?(generated_xcode_build_settings_path)\n    raise \"#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first\"\n  end\n\n  File.foreach(generated_xcode_build_settings_path) do |line|\n    matches = line.match(/FLUTTER_ROOT\\=(.*)/)\n    return matches[1].strip if matches\n  end\n  raise \"FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get\"\nend\n\nrequire File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)\n\nflutter_ios_podfile_setup\n\ntarget 'Runner' do\n  use_frameworks!\n  use_modular_headers!\n  \n  pod 'KeychainAccess'\n  pod 'FBAudienceNetwork','= 6.15.0'\n  \n  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))\n  target 'RunnerTests' do\n    inherit! :search_paths\n  end\nend\n\npost_install do |installer|\n  installer.pods_project.targets.each do |target|\n    flutter_additional_ios_build_settings(target)\n    target.build_configurations.each do |config|\n      config.build_settings['SWIFT_VERSION'] = '5.0'  # required by simple_permission\n      config.build_settings['ENABLE_BITCODE'] = 'NO'\n      # You can remove unused permissions here\n      # for more information: https://github.com/BaseflowIT/flutter-permission-handler/blob/master/permission_handler/ios/Classes/PermissionHandlerEnums.h\n      # e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'\n      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [\n        '$(inherited)',\n\n        ## dart: PermissionGroup.calendar\n        #'PERMISSION_EVENTS=1',\n        \n        ## dart: PermissionGroup.calendarFullAccess\n        #'PERMISSION_EVENTS_FULL_ACCESS=1',\n\n        ## dart: PermissionGroup.reminders\n        #'PERMISSION_REMINDERS=1',\n\n        ## dart: PermissionGroup.contacts\n        #'PERMISSION_CONTACTS=1',\n\n        ## dart: PermissionGroup.camera\n        'PERMISSION_CAMERA=1',\n\n        ## dart: PermissionGroup.microphone\n        'PERMISSION_MICROPHONE=1',\n\n        ## dart: PermissionGroup.speech\n        #'PERMISSION_SPEECH_RECOGNIZER=1',\n\n        ## dart: PermissionGroup.photos\n        'PERMISSION_PHOTOS=1',\n\n        ## The 'PERMISSION_LOCATION' macro enables the `locationWhenInUse` and `locationAlways` permission. If\n        ## the application only requires `locationWhenInUse`, only specify the `PERMISSION_LOCATION_WHENINUSE`\n        ## macro.\n        ##\n        ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]\n        'PERMISSION_LOCATION=1',\n        'PERMISSION_LOCATION_WHENINUSE=0',\n\n        ## dart: PermissionGroup.notification\n        'PERMISSION_NOTIFICATIONS=1',\n\n        ## dart: PermissionGroup.mediaLibrary\n        #'PERMISSION_MEDIA_LIBRARY=1',\n\n        ## dart: PermissionGroup.sensors\n        #'PERMISSION_SENSORS=1',\n\n        ## dart: PermissionGroup.bluetooth\n        #'PERMISSION_BLUETOOTH=1',\n\n        ## dart: PermissionGroup.appTrackingTransparency\n        'PERMISSION_APP_TRACKING_TRANSPARENCY=1',\n\n        ## dart: PermissionGroup.criticalAlerts\n        #'PERMISSION_CRITICAL_ALERTS=1',\n\n        ## dart: PermissionGroup.criticalAlerts\n        #'PERMISSION_ASSISTANT=1',\n      ]\n    end\n  end\nend\n```\n\n那么对照问题截图中的权限：`NSAppleMusicUsageDescription`和`NSLocationAlwaysWhenInUseUsageDescription`\n然后对照`permission_handler`库的权限枚举值：\n![permission_handler podfile macro](https://image.xinwei.ltd/image1740477661568.png)\n\n从红色框中的可以在`Podfile`中对对应的枚举值进行注释（添加#号），没有用到的权限切记要么删除，要么#号注释掉即可。\n\n\n以上。","这里记录一下我在flutter开发过程中遇到的一个问题，希望对有需要的同学有帮助。","https://image.xinwei.ltd/20250225-0427501740475825483.jpeg",499668042977349,{"phone":15,"userId":13,"nickName":16,"vipType":17,"avatar":18,"sign":19,"createdAt":20},"13121171998","全栈老韩",1,"https://image.xinwei.ltd/images/IMG_5430.JPG","全栈工程师，擅长iOS App开发、前端（vue、react、nuxt、小程序&Taro）开发、Flutter、React Native、后端（midwayjs、golang、express、koa）开发、docker容器、seo优化等。","2024-01-01T16:14:30.305Z",2,{"id":21,"name":23},"IT技术",11,{"id":24,"name":26,"parentId":21},"Flutter",[],"",149,0,"ITMS-90683,NSAppleMusicUsageDescription,ios ITMS-90683,ios NSAppleMusicUsageDescription,flutter NSAppleMusicUsageDescription,permission_handler"]