wifi icon indicating copy to clipboard operation
wifi copied to clipboard

Manager doesn't scan in a launch daemon

Open H-Shafiei opened this issue 11 years ago • 13 comments

Hey! I have created a launch daemon and I am using your great classes for managing iPhone's wifi modules. There is a problem though, I am using this tutorial for creating the launch daemons: https://www.chrisalvares.com/blog/7/creating-an-iphone-daemon-part-1/ When I scan for networks the scan callback function isn't called. Do you know why?

again thanks for your great work!

P.S.I think it's because runloops and these stuff but I know almost nothing about them!! :)

H-Shafiei avatar Aug 19 '14 15:08 H-Shafiei

I can't really help you if you don't show me your code. :(

davidmurray avatar Aug 19 '14 19:08 davidmurray

Sorry I didn't have internet access so I am answering after 4 days:) Here is what I do

main.m:

int main (int argc, const char * argv[])
{

@autoreleasepool
{
    NSLog(@"\n\n\n MSManagerStarted 01 \n\n\n");

    // insert code here...
    MSManager *server = [[MSManager alloc] init];

    NSDate *now = [[NSDate alloc] init];
    NSTimer *timer = [[NSTimer alloc] initWithFireDate:now
                                              interval:.01
                                                target:server
                                              selector:@selector(start)
                                              userInfo:nil
                                               repeats:NO];

    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
    [runLoop addTimer:timer forMode:NSDefaultRunLoopMode];
    [runLoop run];
}
return 0;
}

here is MSManager's class start method implementation:

- (void)start
{
       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(managerDidFinishScanning) name:kDMNetworksManagerDidFinishScanning object:nil];
        [[DMNetworksManager sharedInstance] scan];
}

But after it is scanned nothing happens. I mean 'managerDidFinishScanning' isn't called. Can you help?

H-Shafiei avatar Aug 23 '14 11:08 H-Shafiei

Maybe try to use CFRunLoopRun() instead of your NSDate, NSTimer and NSRunLoop code?

Also, can you check the syslog? Maybe you're missing an important entitlement.

davidmurray avatar Aug 23 '14 15:08 davidmurray

There is no problem with the entitlements. Even with CFRunLoopRun() it doesn't work. Any other ideas?

H-Shafiei avatar Aug 23 '14 19:08 H-Shafiei

Can you add an NSLog at the beginning of DMNetworksManager's _scanDidFinishWithError method?

davidmurray avatar Aug 23 '14 20:08 davidmurray

Nothing happens. It gets stuck at _scan method Have you ever used this in a launch daemon?

H-Shafiei avatar Aug 23 '14 20:08 H-Shafiei

Try CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false). Also, make sure that this is the last thing that your main function does.

davidmurray avatar Aug 23 '14 20:08 davidmurray

This doesn't work either:( I can solve my problem another way. What I am trying to do is I want to connect to a given network (the ssid and encryption model and password is given). What i used to do was scan for networks and then if the given said network was scanned then i associated with it. Can I do this another way if there is a problem with scanning?

H-Shafiei avatar Aug 23 '14 20:08 H-Shafiei

I think it's because of the entitlements thing. Can you run ldid -e YourBinary on your daemon? ldidis available in Cydia.

davidmurray avatar Aug 23 '14 20:08 davidmurray

here is the result: `

com.apple.CommCenter.Messages-send com.apple.coretelephony.Identity.get com.apple.developer.ubiquity-container-identifiers com.apple.locationd.preauthorized com.apple.wifi.manager-access keychain-access-groups apple com.apple.preferences com.apple.CommCenter.Messages-send com.apple.coretelephony.Identity.get com.apple.developer.ubiquity-container-identifiers com.apple.locationd.preauthorized com.apple.wifi.manager-access keychain-access-groups apple com.apple.preferences com.apple.CommCenter.Messages-send com.apple.coretelephony.Identity.get com.apple.developer.ubiquity-container-identifiers com.apple.locationd.preauthorized com.apple.wifi.manager-access keychain-access-groups apple com.apple.preferences `

H-Shafiei avatar Aug 23 '14 20:08 H-Shafiei

Hm, looks correct. No idea then.

davidmurray avatar Aug 23 '14 20:08 davidmurray

any help with the network association thing? I mean connect to network without scanning.

H-Shafiei avatar Aug 23 '14 20:08 H-Shafiei

See -[DMNetworksViewController tableView:didSelectRowAtIndexPath:].

davidmurray avatar Aug 23 '14 20:08 davidmurray