Ios sharedApplication需要很长时间才能显示

Ios sharedApplication需要很长时间才能显示,ios,objective-c,ipad,unity3d,native-code,Ios,Objective C,Ipad,Unity3d,Native Code,所以我在上面添加了一些代码,可以在iOS8和95s以及ipad上使用。在更改之前,5s将相当快地加载共享对话框,而ipad将使设备崩溃。添加修复程序后,它们都不会崩溃,但现在ipad显示共享对话框的速度相当快,而5s大约需要1-2分钟才能显示。不知道为什么,也许我找错钱了 #import <Foundation/Foundation.h> extern "C" { void _shareText(const char *text, const char *imgUrl)

所以我在上面添加了一些代码,可以在iOS8和95s以及ipad上使用。在更改之前,5s将相当快地加载共享对话框,而ipad将使设备崩溃。添加修复程序后,它们都不会崩溃,但现在ipad显示共享对话框的速度相当快,而5s大约需要1-2分钟才能显示。不知道为什么,也许我找错钱了

#import <Foundation/Foundation.h>


extern "C" {
    void _shareText(const char *text, const char *imgUrl)
    {
        NSString * message = [NSString stringWithUTF8String:text];
        NSString * urlAddress = [NSString stringWithUTF8String:imgUrl];
        NSURL *url = [NSURL URLWithString:urlAddress];
        NSData *data = [NSData dataWithContentsOfURL:url];
        UIImage *img = [[UIImage alloc] initWithData:data];

        NSMutableArray *sharingItems = [NSMutableArray new];

        if (text) {
            [sharingItems addObject:message];
        }
        if (img) {
            [sharingItems addObject:img];
        }
       UIViewController *qtController = [[UIApplication sharedApplication].keyWindow rootViewController];
       UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];


      if ([activityController respondsToSelector:@selector(popoverPresentationController)] ){
           [qtController presentViewController:activityController animated:YES completion:nil];
           activityController.popoverPresentationController.sourceView = qtController.view;
      }else{
          [qtController presentViewController:activityController animated:YES completion:nil];
      } 
    }
}

该代码是否在主线程上运行?它是unity应用程序的插件。Unity调用看起来像我添加的问题的补充:添加了整个被调用的插件func我对Unity插件不太了解,但我的直觉是你正在从后台线程改变UI。更新需要2分钟的原因是,这大约是您感到厌烦所需的时间,点击屏幕并导致UI更新并绘制新的viewcontroller。在obj-c代码中,如果您在顶部放置断点,然后在Xcode中的调试器中键入po[NSThread isMainThread]它会给你一个明确的答案
[DllImport("__Internal")]
    private static extern void _shareText(string message, string imgUrl);

    public static void InviteRequest(string message, string imgUrl)
    {
        #if UNITY_IOS
        if (Application.platform != RuntimePlatform.OSXEditor)
        {
            _shareText(message, imgUrl);
        }
        #endif
    }