Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AUDIO_SESSION_MICROPHONE not work #67

Open
hc2088 opened this issue Jun 26, 2022 · 13 comments
Open

AUDIO_SESSION_MICROPHONE not work #67

hc2088 opened this issue Jun 26, 2022 · 13 comments

Comments

@hc2088
Copy link

hc2088 commented Jun 26, 2022

audio_session: ^0.1.8

Here is what I added:

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods __dir__
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)

    # ADD THE NEXT SECTION
    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',
        'AUDIO_SESSION_MICROPHONE=0',
        'DISABLE_PUSH_NOTIFICATIONS=1'
      ]
    end
  end
end

but appconnect reply:

ITMS-90683: Missing Purpose String in Info.plist - Your app‘s code references one or more APIs that access sensitive user data. The app‘s Info.plist file should contain a NSMicrophoneUsageDescription key with a user-facing purpose string explaining clearly and completely why your app needs the data. If you're using external libraries or SDKs, they may reference APIs that require a purpose string. While your app might not use these APIs, a purpose string is still required. For details, visit: https://developer.apple.com/documentation/uikit/protecting_the_user_s_privacy/requesting_access_to_protected_resources

@ryanheise
Copy link
Owner

The added section looks correct to me. I'm not sure exactly what may be causing this for you, although I do notice that

  flutter_install_all_ios_pods __dir__

is different from my example:

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))

Not sure if that makes any difference.

One other thing that may be useful is others have reported that even without adding the above code, but instead adding the missing key to Info.plist to describe your microphone usage (even though you don't use the microphone you can add a description like "This app does not use the microphone"), they have had their accepts accepted and the user will never see that description because your app will never actually use any of the microphone APIs.

@hc2088
Copy link
Author

hc2088 commented Jun 26, 2022

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
source 'https://github.com/CocoaPods/Specs.git'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods __dir__
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)

    target.build_configurations.each do |config|
      config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',
        'AUDIO_SESSION_MICROPHONE=0',
        'DISABLE_PUSH_NOTIFICATIONS=1'
      ]
    end
  end
end

The above content is automatically generated by the flutter tools

After many attempts, apple still replied to the same content

Using the vlidate app provided with Xcode, no problems were reported:

App "xxx" successfully validated.

Your apo successfullv passed all validation checks.

@hc2088
Copy link
Author

hc2088 commented Jun 26, 2022

XCODE
Version 13.3 (13E113)

pod --version
1.11.2

flutter --version
Flutter 3.0.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision cd41fdd495 (3 weeks ago) • 2022-06-08 09:52:13 -0700
Engine • revision f15f824b57
Tools • Dart 2.17.3 • DevTools 2.12.2

@ryanheise
Copy link
Owner

We may need to wait until there is more than one report of this to know whether it is an audio_session bug. Until then, my previous advice should apply.

@hc2088
Copy link
Author

hc2088 commented Jun 26, 2022

grep -r recordPermission
Binary file ./Payload/xxx.app/Frameworks/audio_session.framework/audio_session matches

建议:

 else if ([@"getRecordPermission" isEqualToString:call.method]) {
        [self getRecordPermission:args result:result];

把这些也全都加上条件编译。

苹果的扫描可能是直接字符串匹配,即使我们用的是苹果系统的API方法已经加了条件编译,但是可能我们自定义方法,但是苹果可能不那么认为。

- (void)getRecordPermission:(NSArray *)args result:(FlutterResult)result {
#if AUDIO_SESSION_MICROPHONE
    result([self recordPermissionToFlutter:[[AVAudioSession sharedInstance] recordPermission]]);
#else
    result(FlutterMethodNotImplemented);
#endif
}

@ryanheise
Copy link
Owner

I had to google translate that but are you saying that maybe Apple is doing simple string matching and incorrectly picking up the name of one of the plugin's own methods? Feel free to experiment by renaming the method if that's the case, I would be interested to hear if that works for you.

@hc2088
Copy link
Author

hc2088 commented Jun 26, 2022

I had to google translate that but are you saying that maybe Apple is doing simple string matching and incorrectly picking up the name of one of the plugin's own methods? Feel free to experiment by renaming the method if that's the case, I would be interested to hear if that works for you.

It's just a guess, and I'm not sure. I'll try it next time.
It has been proposed today, using the method of adding NSMicrophoneUsageDescription to Info.plist.
Thank you anyway. Your plug-in works well and improves our work efficiency.

@AlekseiAfanasev
Copy link

AlekseiAfanasev commented Jul 11, 2022

Hi!

I'm using just_audio and found that this issue comes from audio_session. Well, the same to me. Here is my Podfile:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)

    # ADD THE NEXT SECTION
    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',
        'AUDIO_SESSION_MICROPHONE=0'
      ]
    end

  end
end

Also didn't work - I still received warning from apple while uploading to TestFlight. Temporary fixed by adding to plist, but I'm not sure it's a clean fix :-)

@ryanheise
Copy link
Owner

The fix was introduced in v0.1.3 and verified as working. Can you report whether the bug is present if you downgrade to that version?

@AlekseiAfanasev
Copy link

It started working after I added

        'PERMISSION_MICROPHONE=0'

to Podfile also. Didn't check v0.1.3, but I think I'll go with this Podfile now as it's working w/o adding key to plist:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)

    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',
        'AUDIO_SESSION_MICROPHONE=0',
        'PERMISSION_MICROPHONE=0'
      ]
    end
  end
end

@ryanheise
Copy link
Owner

Maybe you are using some other plugin that gave you separate instructions to add PERMISSION_MICROPHONE?

@hc2088 is that also the case for you? Is this issue because you're also using another plugin that requires you to disable its microphone code?

@hc2088
Copy link
Author

hc2088 commented Jul 16, 2022

PERMISSION_MICROPHONE

Unlike my case, There is no error of cocoapods. I didn't use PERMISSION_MICROPHONE . What I encountered was that after uploading apple, the IPA package failed to pass the verification. My later solution was in info Plist add "Privacy - Microphone Usage Description"

@ryanheise
Copy link
Owner

As far as I can see, it could certainly be the same in your case.

There is no error of cocoapods.

That is the same in both cases.

I didn't use PERMISSION_MICROPHONE

That is also consistent in both cases. In other words, maybe your app is using another plugin that has its own requirements for what you must add to the Podfile, and so you can't get it to work by just following the requirements of one plugin, you must follow the requirements of all plugins that you use. That is why in @AlekseiAfanasev 's case both AUDIO_SESSION_MICROPHONE was needed (a requirement for audio_session), and PERMISSION_MICROPHONE was also needed (a requirement for some other plugin that @AlekseiAfanasev was using in the same app). If you look at your dependencies and are unsure which one it might be that is causing this, you could share your dependencies below and see if any suspects stand out to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants