macoscocoaosx-yosemitessidcorewlan

using startMonitoringEventWithType: error: in the effort to detect wifi SSID change


Apple seems to introduce quite a change with Yosemite and CoreWLAN framework. I would like to use its new API, quoting the header file:

/*!
 * @method
 *
 * @param type
 * A CWEventType value.
 *
 * @param error
 * An NSError object passed by reference, which upon return will contain the error if an error occurs.
 * This parameter is optional.
 *
 * @result
 * A BOOL value indicating whether or not an error occurred. YES indicates no error occurred.
 *
 * @abstract 
 * Register for specific Wi-Fi event notifications.
 * 
 * @discussion
 * Requires the <i>com.apple.wifi.events</i> entitlement.
 */
- (BOOL)startMonitoringEventWithType:(CWEventType)type error:(out NSError **)error NS_AVAILABLE_MAC(10_10);

and setting CWEventType to: CWEventTypeSSIDDidChange

It says it requires entitlement, but I am not being able to run it on my mac. The error message is:

The app quit unexpectedly. Message from debugger: Terminated due to code signing error.

And my entitlements file (where I suspect the problem to be) is like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.wifi.events</key>
    <true/>
</dict>
</plist>

and I am setting the code signing path in the build setting for the target. And speaking of which, if I exclude the local entitlements file, the app runs but doesn't behave as expected. The API under study returns an error object with following description:

Error Domain=com.apple.wifi.request.error Code=4 "The operation couldn’t be completed. (com.apple.wifi.request.error error 4.)"

It is definitely a mind twister, or at least I hope it is otherwise I am a total idiot. I have a specific App ID for my app in the member center, as well as a specific development profile (although I shouldn't have to since I am using a wildcard dev profile).

Thanks in advance.


Solution

  • It seems that there is currently (31st of July 2015) a bug in CWWiFiClient: entitlements are not properly granted. This even extends to non-sandboxed apps. See this question on the Apple developer forums for more information.

    As a result, we may have to resort to the deprecated API for the time being. syammala provides a good example of how to use the deprecated API.