2017-08-09 146 views
0

我在玩Dart和Flutter,想要在我的Flutter應用程序中顯示媒體選擇器。與Flutter一起使用MPMediaPickerController

我的應用程序的Flutter部分只是一個調用平臺特定代碼的按鈕。我不相信這部分會導致問題,所以我不會添加它。如果被問到,我會編輯我的問題。

這是我的應用程序的目標C部分:

AppDelegate.m

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    FlutterViewController *controller = (FlutterViewController *)self.window.rootViewController; 

    FlutterMethodChannel *audioPlayerChannel = [FlutterMethodChannel methodChannelWithName:@"com.myapp.plugin/audio" binaryMessenger:controller]; 

    [audioPlayerChannel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult _Nonnull result) { 
     if ([call.method isEqualToString:@"showMediaPicker"]) { 
      [self _showMediaPicker]; 

      result(@0); 
     } 
     else { 
      result(FlutterMethodNotImplemented); 
     } 
    }]; 

    return [super application:application didFinishLaunchingWithOptions:launchOptions]; 
} 

- (void)_showMediaPicker { 
    MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio]; 
    MCMediaPickerViewController *delegate = [[MCMediaPickerViewController alloc] init]; 
    FlutterViewController *controller = (FlutterViewController *)self.window.rootViewController; 

    [picker setDelegate:delegate]; 
    [picker setAllowsPickingMultipleItems:NO]; 

    [controller presentViewController:picker animated:YES completion:nil]; 
} 

@end 

MCMediaPickerViewController簡單地實現了MPMediaPickerControllerDelegate協議。

當我在我的設備上運行此代碼並按下按鈕時,空白控制器出現並立即消失,而不顯示選擇器。任何想法爲什麼發生這種情況

預先感謝您。

回答

2

此問題與顫振無關。

嘗試將NSAppleMusicUsageDescription添加到Info.plist。這個iOS之後將開始詢問用戶有關權限的信息。

+0

就是這樣!非常感謝你! – Dayrona