我有这两个错误。我开发了一个在10.10工作的程序,但工厂10.7。我没有在10.8和10.9中测试。 如何纠正问题。 我使用这两种方法进行身份验证和其他方法。 怎么做 ? 改写一切? 谢谢
错误:
2015-09-29 10:32:47.320 PROG [1175:707] - [NSConcreteMutableData base64EncodedStringWithOptions:]:发送到的无法识别的选择器 实例0x7fd209e1c6b0 2015-09-29 10:32:47.321 PROG [1175:707] 未被捕的例外被提出2015-09-29 10:32:47.322 PROG [1175:707] - [NSConcreteMutableData base64EncodedStringWithOptions:]:无法识别的选择器发送到实例0x7fd209e1c6b0 2015-09-29 10:32:47.326 PROG [1175:707](0 CoreFoundation
0x00007fff9158af56 exceptionPreprocess + 198 1 libobjc.A.dylib
0x00007fff8b305d5e objc_exception_throw + 43 2 CoreFoundation
0x00007fff916171be - [NSObject doesNotRecognizeSelector:] + 190 3
CoreFoundation 0x00007fff91577e23 ___ forwarding _ + 371 4 CoreFoundation 0x00007fff91577c38 _CF_forwarding_prep_0 + 232 5 PROG
0x000000010dd8fc20 - [AppDelegate awakeFromNib] + 1056 6
CoreFoundation 0x00007fff91581fb1 - [NSObject performSelector:] + 49 7 CoreFoundation
0x00007fff91581f32 - [NSSet makeObjectsPerformSelector:] + 274 8
AppKit 0x00007fff86eee347 - [NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1245 9 AppKit 0x00007fff86ee48bb loadNib + 322 10 AppKit 0x00007fff86ee3db8 + [NSBundle(NSNibLoading)_loadNibFile:nameTable:withZone:ownerBundle:] + 217 11 AppKit 0x00007fff86ee3cd3 + [NSBundle(NSNibLoading)loadNibFile:externalNameTable:withZone:] + 141 12 AppKit 0x00007fff86ee3c16 + [NSBundle(NSNibLoading)loadNibNamed:owner:] + 364 13 AppKit 0x00007fff87154cd7 NSApplicationMain + 398 14 PROG
0x000000010dd8f7f2 main + 34 15 PROG
0x000000010dd8f7c4 start + 52 16 ??? 0x0000000000000001 0x0 + 1)2015-09-29 10:32:47.326 PROG [1175:707] *由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [NSConcreteMutableData base64EncodedStringWithOptions:]:发送到的无法识别的选择器 实例0x7fd209e1c6b0' * 第一次抛出调用堆栈:(0 CoreFoundation 0x00007fff9158af56 exceptionPreprocess + 198 1 libobjc.A.dylib
0x00007fff8b305d5e objc_exception_throw + 43 2 CoreFoundation
0x00007fff916171be - [NSObject doesNotRecognizeSelector:] + 190 3
CoreFoundation 0x00007fff91577e23 ___ forwarding _ + 371 4 CoreFoundation 0x00007fff91577c38 _CF_forwarding_prep_0 + 232 5 PROG
0x000000010dd8fc20 - [AppDelegate awakeFromNib] + 1056 6
CoreFoundation 0x00007fff91581fb1 - [NSObject performSelector:] + 49 7 CoreFoundation
0x00007fff91581f32 - [NSSet makeObjectsPerformSelector:] + 274 8
AppKit 0x00007fff86eee347 - [NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1245 9 AppKit 0x00007fff86ee48bb loadNib + 322 10 AppKit 0x00007fff86ee3db8 + [NSBundle(NSNibLoading)_loadNibFile:nameTable:withZone:ownerBundle:] + 217 11 AppKit 0x00007fff86ee3cd3 + [NSBundle(NSNibLoading)loadNibFile:externalNameTable:withZone:] + 141 12 AppKit 0x00007fff86ee3c16 + [NSBundle(NSNibLoading)loadNibNamed:owner:] + 364 13 AppKit 0x00007fff87154cd7 NSApplicationMain + 398 14 PROG
0x000000010dd8f7f2 main + 34 15 PROG
0x000000010dd8f7c4 start + 52 16 ??? 0x0000000000000001 0x0 + 1)
感谢您的帮助......和xhruso00 我不知道我是否应该在这里改变我的问题并写下新答案? 谢谢
使用
#import <Foundation/Foundation.h>
@interface NSString (NSStringExtension)
- (id) base64EncodedStringWithOptions:(NSString *)string;
- (NSString *) base64Encoding;
- (NSString *)mh_base64String;
@end
和
#import "NSStringExtension.h"
@implementation NSString (NSStringExtension)
NSUInteger NSAppKitVersionNumber10_8;
NSUInteger NSAppKitVersionNumber;
- (NSString *)mh_base64String
{
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_8) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return [self base64Encoding];
#pragma clang diagnostic pop
}
else {
return [self base64EncodedStringWithOptions:0];
}
}
@end
和
主中的
@implementation AppDelegate
...
//NSString *authenticationValue = [authenticationData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
NSString *authenticationValue = [authenticationData mh_base64String];
...
@end
我有一个错误:
AppDelegate.m:56:57:错误:'NSData'没有可见的@interface声明 选择器'mh_base64String' NSString * authenticationValue = [authenticationData mh_base64String];
我有两个警告:
method definition for 'base64EncodedStringWithOptions:' not found
method definition for 'base64EncodedStringWithOptions:' not found
是正确的吗?
有什么问题?
由于
答案 0 :(得分:0)
您必须检查执行选择器的OS X版本
无法识别的选择器base64EncodedStringWithOptions:在10.9中引入
/ *从接收者的内容创建Base-64编码的NSString 使用给定的选项。 * / - (NSString *)base64EncodedStringWithOptions:(NSDataBase64EncodingOptions)选项NS_AVAILABLE(10_9,7_0);
- (NSString *)base64编码NS_DEPRECATED(10_6,10_9,4_0,7_0);
解决方案A: 为从XIB加载的对象创建一个类别,并调用该方法而不是“base64EncodedStringWithOptions”
- (NSString *)mh_base64String
{
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_8) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return [self base64Encoding];
#pragma clang diagnostic pop
}
else {
return [self base64EncodedStringWithOptions:0];
}
}
解决方案B: 如果你不能做类别,那么使用原始实现的方法调整与上面的实现。
答案 1 :(得分:0)
我在方法中直接添加了awakeFromNib中的方法,如下所示。没关系。
非常感谢你
- (void) awakeFromNib {
...
//NSString *authenticationValue = [authenticationData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
//NSString *authenticationValue = [authenticationData base64Encoding];
NSString *authenticationValue;
// Teste la version du système et affecte la bonne méthode
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_8) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
authenticationValue = [authenticationData base64Encoding];
// NSLog(@"--- <= 10.8 ---- %@", authenticationValue);
#pragma clang diagnostic pop
}
else {
authenticationValue = [authenticationData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
// NSLog(@"----- >= 10.9 ---- %@", authenticationValue);
}
}