解决Unity嵌入iOS后AirPlay投屏失败方法

在Xcode工程中,找到Classes/Unity/DisplayManager.mm文件

- (id)init
{
    if ((self = [super init]))
    {
//        [[NSNotificationCenter defaultCenter] addObserver: self
//         selector: @selector(screenDidConnect:)
//         name: UIScreenDidConnectNotification
//         object: nil
//        ];
//
//        [[NSNotificationCenter defaultCenter] addObserver: self
//         selector: @selector(screenDidDisconnect:)
//         name: UIScreenDidDisconnectNotification
//         object: nil
//        ];

        _displayConnection = [NSMapTable
                              mapTableWithKeyOptions: NSPointerFunctionsStrongMemory | NSPointerFunctionsObjectPointerPersonality
                              valueOptions: NSPointerFunctionsStrongMemory | NSPointerFunctionsObjectPointerPersonality
            ];

        for (UIScreen* screen in[UIScreen screens])
            [self registerScreen: screen];

        _mainDisplay = self[[UIScreen mainScreen]];
    }
    return self;
}

注释掉2个添加观察者的消息就可以了。

你可能感兴趣的:(解决Unity嵌入iOS后AirPlay投屏失败方法)