2012-11-09 23 views
5

निम्न विधि का उपयोग और में 99.5% मामलों, लेकिन बहुत कम उपयोगकर्ताओं के लिए अच्छी तरह से काम AppStore रिपोर्ट वे मैक पते नहीं मिल सकता है (हम हर सर्वर कॉल प्रमाणित करने के लिए पहचानकर्ता उपयोग करें)।आईफोन जिसके लिए मामलों में मैक पता सफलता नहीं मिल सकती है?

असफल मामला आईओएस संस्करण 5.0.1 के साथ आईफोन 4 एस पर आधारित है।

अरे दोस्तों,

क्या आप जानते हैं जो मामले (कम स्मृति के अलावा) के लिए यह असफल हो जायेगी? किसी भी विचार या चर्चा की सराहना की जाएगी। धन्यवाद।

/* Original source code courtesy John from iOSDeveloperTips.com */ 

#include <sys/socket.h> 
#include <sys/sysctl.h> 
#include <net/if.h> 
#include <net/if_dl.h> 

- (NSString *)getMacAddress 
{ 
    int     mgmtInfoBase[6]; 
    char    *msgBuffer = NULL; 
    NSString   *errorFlag = NULL; 
    size_t    length; 

    // Setup the management Information Base (mib) 
    mgmtInfoBase[0] = CTL_NET;  // Request network subsystem 
    mgmtInfoBase[1] = AF_ROUTE;  // Routing table info 
    mgmtInfoBase[2] = 0;    
    mgmtInfoBase[3] = AF_LINK;  // Request link layer information 
    mgmtInfoBase[4] = NET_RT_IFLIST; // Request all configured interfaces 

    // With all configured interfaces requested, get handle index 
    if ((mgmtInfoBase[5] = if_nametoindex("en0")) == 0) 
     errorFlag = @"if_nametoindex failure"; 
    // Get the size of the data available (store in len) 
    else if (sysctl(mgmtInfoBase, 6, NULL, &length, NULL, 0) < 0) 
     errorFlag = @"sysctl mgmtInfoBase failure"; 
    // Alloc memory based on above call 
    else if ((msgBuffer = malloc(length)) == NULL) 
     errorFlag = @"buffer allocation failure"; 
    // Get system information, store in buffer 
    else if (sysctl(mgmtInfoBase, 6, msgBuffer, &length, NULL, 0) < 0) 
    { 
     free(msgBuffer); 
     errorFlag = @"sysctl msgBuffer failure"; 
    } 
    else 
    { 
     // Map msgbuffer to interface message structure 
     struct if_msghdr *interfaceMsgStruct = (struct if_msghdr *) msgBuffer; 

     // Map to link-level socket structure 
     struct sockaddr_dl *socketStruct = (struct sockaddr_dl *) (interfaceMsgStruct + 1); 

     // Copy link layer address data in socket structure to an array 
     unsigned char macAddress[6]; 
     memcpy(&macAddress, socketStruct->sdl_data + socketStruct->sdl_nlen, 6); 

     // Read from char array into a string object, into traditional Mac address format 
     NSString *macAddressString = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X", 
             macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]]; 
     NSLog(@"Mac Address: %@", macAddressString); 

     // Release the buffer memory 
     free(msgBuffer); 

     return macAddressString; 
    } 

    // Error... 
    NSLog(@"Error: %@", errorFlag); 

    return errorFlag; 
} 

किसी भी मदद की बहुत सराहना की जाती है।

+0

इस मुद्दे पर कोई अनुभव? – jianhua

+0

क्या आप इस त्रुटि को फिर से बनाने में सक्षम हैं? मैंने अभी आईफोन 4 एस 5.1.1 पर अपने कोड का परीक्षण किया है (मुझे बस हाथ करना था) और यह सिर्फ बेवकूफ काम करता है। मैं व्यक्तिगत रूप से उपयोग की जाने वाली विधियों की सिफारिश कर सकता हूं, लेकिन यह आपके जैसा ही है ... –

+1

en0 केवल वाईफ़ाई इंटरफ़ेस है? क्या होता है यदि डिवाइस पर वह इंटरफ़ेस नीचे है? – jaseelder

उत्तर

0

आईफोन को आईओएस 5 में अपग्रेड करने के बाद मैं इस तरह की स्थिति में भाग गया, समस्या कुख्यात वाईफाई बग थी। आप इस जवाब को पसंद नहीं करेंगे, लेकिन एकमात्र समाधान डिवाइस को ऐप्पल पर वापस लेना था और एक नया काम करना था जो ठीक से काम करता था। मैक एड्रेस लुकअप विफल होने पर कोड को क्रैश नहीं बदला जा सकता है, लेकिन जब आरईएसटी कॉल को एक अद्वितीय पहचानकर्ता की आवश्यकता होती है तो इससे मदद नहीं मिलती है। एक डेवलपर के रूप में, आप एक चट्टान और एक कठिन जगह के बीच फंस गए हैं।

+0

हां, आप सही हैं, इस तरह के मुद्दे पर समय की आवश्यकता नहीं है। – jianhua