请问这是什么语法,方法前面既没有+,也没有-,是省掉了+,还是省掉了-@implementation UIDevice (IOKit_Extensions)
#pragma  IOKit Utils
NSArray *getValue(NSString *iosearch)
{
    mach_port_t          masterPort;
    CFTypeID             propID = (CFTypeID) NULL;
    unsigned int         bufSize;
    
    kern_return_t kr = IOMasterPort(MACH_PORT_NULL, &masterPort);
    if (kr != noErr) return nil;
    
    io_registry_entry_t entry = IORegistryGetRootEntry(masterPort);
    if (entry == MACH_PORT_NULL) return nil;
    
    CFTypeRef prop = IORegistryEntrySearchCFProperty(entry,kIODeviceTreePlane, (__bridge CFStringRef) iosearch, nil,kIORegistryIterateRecursively);
    if (!prop) return nil;
    
    propID = CFGetTypeID(prop);
    if (!(propID == CFDataGetTypeID()))
    {
        mach_port_deallocate(mach_task_self(), masterPort);
        return nil;
    }
    
    CFDataRef propData = (CFDataRef) prop;
    if (!propData) return nil;
    
    bufSize = CFDataGetLength(propData);
    if (!bufSize) return nil;
    
    //NSString *p1 = [[[NSString alloc] initWithBytes:CFDataGetBytePtr(propData) length:bufSize encoding:1] autorelease];
    NSString *p1 = [[NSString alloc]initWithBytes:CFDataGetBytePtr(propData) length:bufSize encoding:NSUTF8StringEncoding] ;
    mach_port_deallocate(mach_task_self(), masterPort);
    return [p1 componentsSeparatedByString:@"/0"];
}

解决方案 »

  1.   

    这是C语言的方法,OC是直接支持C的,如果要文件后缀改成mm,也是能直接支持C++的
      

  2.   

    我是在这里看到的:http://www.cnblogs.com/pengyingh/articles/2488181.html
    我使用后,报错;
    Undefined symbols for architecture armv7:
      "_IOMasterPort", referenced from:
          _getValue in network.o
      "_IORegistryGetRootEntry", referenced from:
          _getValue in network.o
      "_IORegistryEntrySearchCFProperty", referenced from:
          _getValue in network.o
    ld: symbol(s) not found for architecture armv7
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    为什么C和OC混在一个文件里,会有这个错误?哪里还需要设置吗?
      

  3.   

    IOKit框架没有导入进来
      

  4.   

    事实上,从Xcode 6开始貌似就不能使用IOKit框架了
      

  5.   

    这是c语言的函数声明。在oc 中可以混编c or c++ . 如果是与c++混编,但需要告知编译器使用c++编译器来编译,用于分区的标志是将文件的扩展名改成.mm