didDiscoverPeripheral is not called after upgrading from iOS 7 to iOS 8 - core-bluetooth

I am calling scanForPeripheralsWithServices from didFinishLaunchingWithOptions callback of AppDelegate. The code looks like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
NSLog(#"didFinishLaunchingWithOptions");
// Override point for customization after application launch.
cm = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[cm scanForPeripheralsWithServices:nil
options:nil];
}
- (void) centralManager:(CBCentralManager*)central didDiscoverPeripheral:(CBPeripheral*)peripheral advertisementData:(NSDictionary*)advertisementData RSSI:(NSNumber*)RSSI{
NSLog(#"Did discover peripheral %#", peripheral.name);
[cm stopScan];
}
Before upgrading to iOS 8 everything was working well, however after the upgrade (exactly the same code, no single line was changed) I am not getting any error, but also didDiscoverPeripheral is not being called.

I appears that the major change which has occurred with Core Bluetooth in iOS 8 is that the BLE stack isn't powered on until you try to connect (or possible issue some other command).
CBCentralManager *cbCentralManager;
[cbCentralManager scanForPeripheralsWithServices:...];
This call used to issue a warning visible in the Xcode debug log saying that the central manager needed to be powered-up before it could be used. However, this warning was always a catch-22 — the only way to power-on the central manager was to send it a message, and the only way for it to process a message was for it to be powered-on.
Apple seems to have resolved this problem by handling power-on a bit differently. Now, after issuing the above command the central manager tells its delegate that its state changed via centralManagerDidUpdateState:.
We resolved the problem you describe by responding to centralManagerDidUpdateState: by re-issuing the scanForPeripherals... message.

Related

WidgetKit: deep-link from widget to macOS app

I am adopting my iOS widget to my Mac app, and one thing I can't figure out is when I do a deep-link from the widget to the Mac app, where would that get detected? On iOS, it calls:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
But I can't find any equivalent method in the NSApplicationDelegate. The closest method is
- (void)application: (NSApplication *)application openURLs:(nonnull NSArray<NSURL *> *)urls
But this doesn't get invoked from the widget's Link.
Is there some other way to handle this on macOS? Do I need to configure something in particular for the openURLs method to be called?
EDIT:
After more testing, I've realized that the application: openURLs method should be called, whether through the widget Link or directly called using the URL scheme (as defined in the Info.plist). I verified this with another test app as well, where I can use [[NSWorkspace sharedWorkspace] openURL: testURL] to open the test app and the application: openURLs DOES get called. But it's not working for my main app for some reason, even though I've followed the same steps and defined the URL scheme in CFBundleURLTypes in the Info.plist file. The main app was created many years ago, whereas the test app was created just today.
Any ideas why the openURLs method isn't getting called in my main app?

Dose CoreBluetooth work on IOS6.0,IOS6.1,IOS6.1.2?

i am working on bluetooth4.0 , but i found that CoreblueTooth cannot run on iOS 6+,my iphone4s is IOS 6.1.2.
it cannot find any device(i am sure the device is power on), the Log as below every time:
CoreBluetooth[WARNING] is not powered on
Dose anyone have encounter this issue?
The status CBCentralManagerStatePoweredOn means not only that Bluetooth is turned on, but also that your instance of CBCentralManager or CBPeripheralManager is ready to use. You must initialize your manager, then wait for its state to change before using it. For example, if you are acting as a Central, you would initialize it with the following:
centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
And implement the delegate method centralManagerDidUpdateState:
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
if (central.state == CBCentralManagerPoweredOn)
{
//do your stuff, it's ready
}
}
I'm testing on a iPhone 4S running 6.0.1. The iPhone is in central role and I don't see your warning.
Can you please be more specific about what you're doing?
- Are you in peripheral or central role?
Have you initialized the CBCentralManager (if you're a central) as follows?
centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
I hope I could help you

App won't open after clicking on remote notification'

I have a Problem with remote notifications and OSx 10.8.
I enabled the remote push notifications successful. They also were delivered to my system, but when I try to click one nothing happens.
Also for this app update I had to enable sandboxing!
The Mac-Console log:
29.08.12 11:03:50,600 usernoted[194]: Cannot find originating application to launch for event action. file://localhost/Users/clueckler/Library/Developer/Xcode/DerivedData/mysms_OSX_Client-bcaianxrdhpztmdcnsrgzqdtqmvi/Build/Products/Debug/mysms_test.app/ is not the same app as the one that sent the original notification.
29.08.12 11:03:50,600 usernoted[194]: Error finding application com.mysms.osx.client.test.
I thought it was a problem of the AdHoc-Test or something. So I tried to submit it to the AppStore with success!
But the same problem appears with the AppStore Version (now I removed it from store ...)
Is there a solution for this problem?
EDIT (Code Information):
- (void)awakeFromNib {
// Register app for remote notification
[[NSApplication sharedApplication] registerForRemoteNotificationTypes:(NSRemoteNotificationTypeBadge | NSRemoteNotificationTypeSound | NSRemoteNotificationTypeAlert)];
}
- (void)application:(NSApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
//Post token to server
}

Never getting iCloud change notifications

I am working on Core Data syncing over iCloud between two Mac applications. I have it mostly working (based on http://timroadley.com/2012/04/03/core-data-in-icloud/) - data is being synced, but I'm never getting the content change notification I need to merge the changes into my local context.
In my AppDelegate's managedObjectContext method:
NSManagedObjectContext * moc = [[NSManagedObjectContext alloc]
initWithConcurrencyType:NSMainQueueConcurrencyType];
[moc performBlockAndWait:
^{
[moc setPersistentStoreCoordinator:coordinator];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(mergeChangesFrom_iCloud:)
name:NSPersistentStoreDidImportUbiquitousContentChangesNotification
object:coordinator];
}];
My observer function never gets called:
- (void) mergeChangesFrom_iCloud:(NSNotification*) notification
{
NSLog(#"Merging changes from iCloud");
// everything past here is irrelevent - this log message never appears
The data store is most certainly being synced - deleting a record in app A and forcing a table reload in app B results in a Core Data fault failure as expected for unmerged changes. Quitting and restarting app B shows the correctly updated data.
A breakpoint on the addObserver call shows it is being called. A breakpoint in mergeChangesFrom_iCloud shows that it is not.
Why is the coordinator apparently never sending the NSPersistentStoreDidImportUbiquitousContentChangesNotification as the documentation (and tutorials) claim it should? Where can I begin debugging this?
Update
The mystery deepens. Using the Core Foundation function shown here - NSNotificationCenter trapping and tracing all NSNotifications - I do not see NSPersistentStoreDidImportUbiquitousContentChangesNotification appear at all among the mass of notifications flying by.
It looks like it's not being posted at all - nor do I see any other Core Data related notifications after the initial load happens on startup.

NSURLConnection fails after upgrade to iOS 5

I have a very simple NSURLConnection call that works perfectly in all iOS versions except iOS 5. Since this is a 'sendSynchronousRequest' call, there are no NSURL delegates declared anywhere in the app (the response should come directly back to this method call). Also, because this is a sendSynchronousRequest, there are no 'didReceiveData' or other NSURL-associated methods implemented in the app.
Here is the offending line of code:
NSData *response = [NSURLConnection sendSynchronousRequest: serviceRequest returningResponse:nil error:nil];
When I step through the code in the debugger, I can confirm that app is sending the request, and that the server is receiving the request. I can also confirm that the server is then sending a response back to the client.
This was all working perfectly until I upgraded to iOS 5. Now, after the update to iOS5, the NSData variable (response) is never receiving anything and always comes back with 0 bytes.
Other than the update to iOS5, there have been no code changes at all.
There were several changes made to the NSURLConnection class in iOS 5. In particular, several delegate methods that were deprecated. I experienced a similar issue and it was caused by one of the delegate methods no longer being called. If this sounds like your issue, take a look at the formal delegate protocols NSURLConnectionDelegate and NSURLConnectionDataDelegate.
I had the same problem using a custom Web server. The problem turned out to be an invalid header in the response. I changed:
HTTP/1.1 200/OK
to:
HTTP/1.1 200 OK
iOS 5 now accepts the response. Check your packet capture. You may have the same or similar problem.

Resources