将这个问题解决了几天,最后不得不屈服并寻求帮助。 我正在构建一个导出到Xcode的Unity游戏。游戏没有使用Objective C进行直接导出,而是转换为Swift 4.0项目。 Check Here for more info on how its done。 我已经以这种方式构建了多个应用程序,并且到目前为止还没有遇到这个问题,但是以前的应用程序都没有推送通知。
几件事值得一提:
因此,我设法查明了错误的开始位置以及与此类有关的此类LocalNotificationAppController.h
#import <UIKit/UIKit.h>
#import <Foundation/NSURLConnection.h>
#import <Foundation/NSURL.h>
#import "UnityAppController.h"
extern bool _unityAppReady;
@interface LocalNotificationAppController : UnityAppController
{}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler;
@end
@implementation LocalNotificationAppController
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler
{
[self notifyUnityOfAction:identifier inNotification:notification completionHandler:completionHandler];
}
- (void)notifyUnityOfAction:(NSString*)identifier inNotification:(UILocalNotification*)notification completionHandler:(void (^)())completionHandler
{
if (_unityAppReady)
{
NSArray *parts = [identifier componentsSeparatedByString:@":"];
if (parts.count == 3) {
NSString *gameObject = parts[0];
NSString *handlerMethod = parts[1];
NSString *action = parts[2];
UnitySendMessage(strdup([gameObject UTF8String]), strdup([handlerMethod UTF8String]), strdup([action UTF8String]));
UnityBatchPlayerLoop();
}
if (completionHandler != nil)
completionHandler();
}
else
{
NSNotificationCenter * __weak center = [NSNotificationCenter defaultCenter];
id __block token = [center addObserverForName:@"UnityReady" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
_unityAppReady = true;
[center removeObserver:token];
[self notifyUnityOfAction:identifier inNotification:notification completionHandler:completionHandler];
}];
}
}
@end
//IMPL_APP_CONTROLLER_SUBCLASS(LocalNotificationAppController)
链接到
#define IMPL_APP_CONTROLLER_SUBCLASS(ClassName) \
@interface ClassName(OverrideAppDelegate) \
{ \
} \
+(void)load; \
@end \
@implementation ClassName(OverrideAppDelegate) \
+(void)load \
{ \
extern const char* AppControllerClassName; \
AppControllerClassName = #ClassName; \
} \
@end
在UnityAppController.h内部
因此构建失败并出现以下错误:
体系结构arm64的未定义符号: “ _AppControllerClassName”,引用自: + [LocalNotificationAppController.o中的[LocalNotificationAppController(OverrideAppDelegate)负载] ld:找不到架构arm64的符号
,如果在LocalNotificationAppController中将此行注释掉:
//IMPL_APP_CONTROLLER_SUBCLASS(LocalNotificationAppController)
该版本可以运行,但是在应用程序应寻求许可的确切位置发生了线程异常。