【发布时间】:2021-08-17 07:52:31
【问题描述】:
我在 AppDelegate.m 中声明了一个新方法,比如:
-(void):(UIApplication *)aMethod :(NSDictionary *)launchOptions{
......
[UMessage registerForRemoteNotificationsWithLaunchOptions:launchOptions Entity:entity
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
}else{
}
}];
......
}
在我的 AppDelegate.h 中:
- (void)aMethod;
在我的 anotherClass.m 中:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate aMethod];
当我在 anotherClass.m 中运行代码时,我得到了错误。有谁知道我错在哪里?
【问题讨论】:
-
你声明的函数接受一个字典并返回一个指向
UIApplication的指针。您正在调用的函数没有传递任何参数。该错误表示未找到名为aMethod的不接受任何参数的方法 -
复制粘贴完整的错误信息。选择器应该有帮助。但如前所述,
[appDelegate aMethod]可以,如果您声明:-(void)aMethod{...}。哦,在Objective-C中,不要在之前什么都没有的方法中使用:,这是一种冗长的语言,所以实际上-(void):(UIApplication *)aMethod :(NSDictionary *)launchOptions完全不清楚......它可能是-(void)aMethodWithApplication: (UIApplication *)application andLaunchOptions:(NSDictionary *)launchOptions然后是[appDelegate aMethodWithApplication: [UIApplication sharedApplication] andLaunchOptions: ???]
标签: ios objective-c react-native-ios appdelegate