Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manager doesn't scan in a launch daemon #13

Open
H-Shafiei opened this issue Aug 19, 2014 · 13 comments
Open

Manager doesn't scan in a launch daemon #13

H-Shafiei opened this issue Aug 19, 2014 · 13 comments

Comments

@H-Shafiei
Copy link

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!! :)

@davidmurray
Copy link
Owner

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

@H-Shafiei
Copy link
Author

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?

@davidmurray
Copy link
Owner

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.

@H-Shafiei
Copy link
Author

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

@davidmurray
Copy link
Owner

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

@H-Shafiei
Copy link
Author

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

@davidmurray
Copy link
Owner

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

@H-Shafiei
Copy link
Author

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?

@davidmurray
Copy link
Owner

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

@H-Shafiei
Copy link
Author

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 `

@davidmurray
Copy link
Owner

Hm, looks correct. No idea then.

@H-Shafiei
Copy link
Author

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

@davidmurray
Copy link
Owner

See -[DMNetworksViewController tableView:didSelectRowAtIndexPath:].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants