[UIDevice deviceType]: unrecognized selector sent to class 0x23a2421b0

1k views Asked by At

I'm using PortSIP SDK for my iOS app.

In my App when i click call button the app gives me that error.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIDevice deviceType]: unrecognized selector sent to class 0x23a2421b0'

I think my app can't get device type.

Any advice please ? What's that error saying ?

3

There are 3 answers

0
bruno55 On

I had the same error in a demo using PortSIPSDK and the problem was a problem in configuration. From docs: http://www.portsip.cn/docs/html_man/ios/html/index.html

  1. Add "-ObjC" to "Build Settings"-> "Other Linker Flags"
0
KingHodor On

Normally, UIDevice does not have deviceType member. There should be an extension in the PortSIP SDK. You should check the source code. Probably, they do not cover all cases. But you can use the below code to detect your device type.

#include <sys/sysctl.h>
#include <sys/utsname.h>


- (NSString *) platformString{

NSLog(@"[UIDevice currentDevice].model: %@",[UIDevice currentDevice].model);
NSLog(@"[UIDevice currentDevice].description: %@",[UIDevice currentDevice].description);
NSLog(@"[UIDevice currentDevice].localizedModel: %@",[UIDevice currentDevice].localizedModel);
NSLog(@"[UIDevice currentDevice].name: %@",[UIDevice currentDevice].name);
NSLog(@"[UIDevice currentDevice].systemVersion: %@",[UIDevice currentDevice].systemVersion);
NSLog(@"[UIDevice currentDevice].systemName: %@",[UIDevice currentDevice].systemName);
NSLog(@"[UIDevice currentDevice].batteryLevel: %f",[UIDevice currentDevice].batteryLevel);      
struct utsname systemInfo;
uname(&systemInfo);
NSLog(@"[NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]: %@",[NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]);
NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];

    if ([platform isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";
if ([platform isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
if ([platform isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
if ([platform isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
if ([platform isEqualToString:@"iPhone3,2"])    return @"iPhone 4 CDMA";
if ([platform isEqualToString:@"iPhone3,3"])    return @"Verizon iPhone 4";
if ([platform isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
if ([platform isEqualToString:@"iPhone5,1"])    return @"iPhone 5 (GSM)";
if ([platform isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone5,3"])    return @"iPhone 5c (GSM)";
if ([platform isEqualToString:@"iPhone5,4"])    return @"iPhone 5c (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone6,1"])    return @"iPhone 5s (GSM)";
if ([platform isEqualToString:@"iPhone6,2"])    return @"iPhone 5s (GSM+CDMA)";
if ([platform isEqualToString:@"iPhone7,2"])    return @"iPhone 6";
if ([platform isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
if ([platform isEqualToString:@"iPod1,1"])      return @"iPod Touch 1G";
if ([platform isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";
if ([platform isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";
if ([platform isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";
if ([platform isEqualToString:@"iPod5,1"])      return @"iPod Touch 5G";
if ([platform isEqualToString:@"iPad1,1"])      return @"iPad";
if ([platform isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
if ([platform isEqualToString:@"iPad2,2"])      return @"iPad 2 (Cellular)";
if ([platform isEqualToString:@"iPad2,3"])      return @"iPad 2 (Cellular)";
if ([platform isEqualToString:@"iPad2,4"])      return @"iPad 2 (WiFi)";
if ([platform isEqualToString:@"iPad2,5"])      return @"iPad Mini (WiFi)";
if ([platform isEqualToString:@"iPad2,6"])      return @"iPad Mini (Cellular)";
if ([platform isEqualToString:@"iPad2,7"])      return @"iPad Mini (Cellular)";
if ([platform isEqualToString:@"iPad3,1"])      return @"iPad 3 (WiFi)";
if ([platform isEqualToString:@"iPad3,2"])      return @"iPad 3 (Cellular)";
if ([platform isEqualToString:@"iPad3,3"])      return @"iPad 3 (Cellular)";
if ([platform isEqualToString:@"iPad3,4"])      return @"iPad 4 (WiFi)";
if ([platform isEqualToString:@"iPad3,5"])      return @"iPad 4 (Cellular)";
if ([platform isEqualToString:@"iPad3,6"])      return @"iPad 4 (Cellular)";
if ([platform isEqualToString:@"iPad4,1"])      return @"iPad Air (WiFi)";
if ([platform isEqualToString:@"iPad4,2"])      return @"iPad Air (Cellular)";
if ([platform isEqualToString:@"i386"])         return @"Simulator";
if ([platform isEqualToString:@"x86_64"])       return @"Simulator";
return @"Unknown";
}
0
AamirR On

My issue was exactly as Bruno posted, since my target was Swift Package based C++ library, adding following linkerSettings to Package.swift fixed the issue

linkerSettings: [
    .unsafeFlags([
        "-ObjC"
    ]),
]

My first attempt was adding .define("OTHER_LDFLAGS",to: "-ObjC") in cSettings, but that did not solve the issue, that might be because I was also using cxxSettings, not sure though. Anyways... here is my final Package.swift screenshot just incase

enter image description here