Asked  6 Months ago    Answers:  5   Viewed   27 times

How to programmatically get an iPhone's MAC address and IP address?



NOTE As of iOS7, you can no longer retrieve device MAC addresses. A fixed value will be returned rather than the actual MAC

Somthing I stumbled across a while ago. Originally from here I modified it a bit and cleaned things up.


And to use it


int i;
NSString *deviceIP = nil;
for (i=0; i<MAXADDRS; ++i)
    static unsigned long localHost = 0x7F000001;        //
    unsigned long theAddr;

    theAddr = ip_addrs[i];

    if (theAddr == 0) break;
    if (theAddr == localHost) continue;

    NSLog(@"Name: %s MAC: %s IP: %sn", if_names[i], hw_addrs[i], ip_names[i]);

        //decided what adapter you want details for
    if (strncmp(if_names[i], "en", 2) == 0)
        NSLog(@"Adapter en has a IP of %s", ip_names[i]);

Adapter names vary depending on the simulator/device as well as wifi or cell on the device.

Tuesday, June 1, 2021
answered 6 Months ago

There is no public API to get this information.

If this is an internal or jailbreak application you can get the value of the kLockdownBluetoothAddressKey key via liblockdown.dylib

Friday, July 30, 2021
answered 4 Months ago

Sorry to say that but Apple is damn conservative.You cannot use or change the ringtones available programmatically.

Tuesday, August 24, 2021
answered 3 Months ago

This issue is resolved by checking the class of the destination view controller before trying to access one of its properties:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    DestController *vc = segue.destinationViewController;

    if ([dvc isKindOfClass:[DestController class]])
        dvc.propertyName = @"Property Value";
        // do something else

Taken from a solution in this thread.

Monday, October 25, 2021
answered 1 Month ago

Problem finally solved. I'm not sure what exactly caused the issue (Masonry [constraints framework] or iOS8 changes to UILabel), but the solution was to change the view hierarchy. I created another UIView that contains both UILabel and my UIView (drawn beak) instead of adding the UIView to UILabel as subview. Now drawRect method is called both on iOS7 and iOS8.

Previous hierarchy:
UIViewController View->Custom UILabel->MyView

New hierarchy:
UIViewController View->Container UIView->Custom UILabel & MyView

To sum up, if your drawRect method is not called on iOS8, and you are adding some UIView to UILabel as subview, try to use some container which will contain both UIView and UILabel.

Thursday, November 11, 2021
Greg Malcolm
answered 3 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :