所以我添加了一些代码来处理ios 8和9(5s和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 Called功能:
[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
}