iOS Bluetooth State Preservation and Restoration's DUPLICATE ISSUE -25299 - ios

I am having an issue when instantiating my CBCentralManager. I get a "duplicate issue" message when monitoring it from the iOS console (it does not show in the XCode console).
I've tried updating the queue name and the restoration key id without success. This is how I instantiate my Central Manager:
CBCentralManager *central = [[CBCentralManager alloc] initWithDelegate: self
queue: dispatch_queue_create("com.mydomain.myapp.scanner", NULL)
options: #{
CBCentralManagerOptionRestoreIdentifierKey: #"hexa-string-comes-here"
}];
And those are the errors I am getting:
CKLs-iPhone-5S securityd[78] :
securityd_xpc_dictionary_handler MyApp[2571] add The operation
couldn’t be completed. (OSStatus error -25299 - duplicate item
O,genp,E99372E2,L,ck,X2W6M5UYJ9.com.mydomain.myapp,0,acct,svce,v_Data,20151218165347.298588Z,2CAE5650)
CKLs-iPhone-5S MyApp[2571] : SecOSStatusWith
error:[-25299] The operation couldn’t be completed. (OSStatus error
-25299 - Remote error : The operation couldn’t be completed. (OSStatus error -25299 - duplicate item
O,genp,E99372E2,L,ck,X2W6M5UYJ9.com.mydomain.myapp,0,acct,svce,v_Data,20151218165347.298588Z,2CAE5650))
Any ideas?

If you want to use the CBCentralManagerOptionRestoreIdentifierKey, you must
implement the method
// in Objective-C
- (void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionary<NSString *, id> *)dict
// or in Swift
func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : AnyObject])
from CBCentralManagerDelegate, and
use the background mode Uses Bluetooth LE accessories set up in Xcode:

This may be related to known Keychain issue. (However, it is only a guess that this is Keychain coming from Security log in your app). OSStatus duplicate item appears when there is already a registered item with all attributes supplied along with the item. So what could happen in here is:
keychain failed to delete last restoration id - item is left in keychain.
register for the restoration with the same id
keychain tries to save item.
it returns duplicate item error

Related

iOS 16 FairPlay Changes

Are there any changes in FairPlay logic? My app has FairPlay protected Videos and Audio, they work perfectly until iOS 15.7, but in iOS 16
makeStreamingContentKeyRequestData is throwing me following error :
Error Domain=CoreMediaErrorDomain Code=-19152 "(null)"
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed"
UserInfo={NSLocalizedFailureReason=An unknown error occurred (-19156), NSLocalizedDescription=The operation could not be completed,
NSUnderlyingError=0x280deac10 {Error Domain=NSOSStatusErrorDomain Code=-19156 "(null)"}}
What could be the possible reason for this and solution?
Thanks in Advance
Function streamingContentKeyRequestDataForApp is deprecated on iOS 15 according to documentation. Use function makeStreamingContentKeyRequestData that is specified in new function documentation. Here is an example usage:
func makeStreamingContentKeyRequestData(
forApp appIdentifier: Data,
contentIdentifier: Data?,
options: [String : Any]? = nil,
completionHandler handler: #escaping (Data?, Error?) -> Void
)
We are using AVContentKeySession for downloading, met with the same error, and fixed it. For our case, the issue was as following.
Issue observed:
On iOS16.0.3, 12s later after "license request" was triggered firstly by app during downloading, "license request" would be triggered again by AVFoundation framework
("contentKeySession(_ session: AVContentKeySession, didProvide keyRequest: AVContentKeyRequest)" was called again), and then error “-19152“ wad reported quickly by framework.
Error log:
contentKeySession(_:contentKeyRequest:didFailWithError:), line: XXX,
message: XXX, url: XXX, error is Domain=CoreMediaErrorDomain
Code=-19152 "(null)"
On iOS15.6.1, after "license request" was triggered
by app during downloading, framework would not trigger any "license request" again.
Root cause:
iOS Framework API(AVContentKeySession & AVPersistableContentKeyRequest) behaviors changed on iOS16.
Solution:
Add “keyRequest.processContentKeyResponse(keyResponse)” after CKC has been downloaded on iOS16+.
On iOS11 - iOS15, we didn't call it after downloading, instead we only save persistentKeyData locally, and called processContentKeyResponse when playing. That always worked fine on these iOS versions.
But on iOS16 and above(until iOS16.1 Beta4 by now), the old process would trigger framework error. So we added this fix.
The issue I had was that the keyRequest.options was not getting set as it showed up nil (in iOS 16 for whatever weird reason).
I'm passing the correct options to
processContentKeyRequest(withIdentifer identifier: Any?, initializationData: Data?, options: [String : Any]? = nil).
But in the ContentKeyDelegate functions they are showing otherwise. So, my workaround is just using a global options dictionary for storing the license URL and asset data. You can use any storage method you prefer.
I have solved the issue, the issue was with duplicate EXT tags in m3u8 files which somehow worked for iOS 15 since it picked information from the first tag whereas in iOS 16 it was using all the tags and causing a Error

A weird message in CoreBluetooth / CBCentralManagerDelegate

In my implementation of the CBCentralManagerDelegate protocol, I have the following function.
func centralManager(_ central: CBCentralManager,
didDisconnectPeripheral peripheral: CBPeripheral,
error: Error?) {
print(#function)
if error != nil {
print("Error in \(#function) :\n\(error!)")
return
}
......
// More useful code irrelevant to the question.
}
When the above function is called I can see the message below in the Xcode debugging console.
centralManager(_:didDisconnectPeripheral:error:)
Error in centralManager(_:didDisconnectPeripheral:error:) :
Error Domain=CBErrorDomain Code=7 "The specified device has disconnected from us."
UserInfo={NSLocalizedDescription=The specified device has disconnected from us.}
Here is my question:
I must be missing something (because too simple or too subtle), but why does is show an error because "The specified device has disconnected from us."
In the centralManager:didDisconnectPeripheral function, what else could I expect other than the device being disconnected?
I hope some enlighted expert can bring some light an explain why this is so.
As per the Apple documentation:
If the disconnection was not initiated by cancelPeripheralConnection(_:), the cause is detailed in error.
I.e if You disconnect then you get no error but if They disconnect you see that through the error.
Source: https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerdelegate/1518791-centralmanager

Swift Core data can't store data second time : Cocoa error 1560

I have core data and three object inside them. Let say I have objects: Parent, Child, Item.
Parent have Set<Child>, Child have Set<Item>, so with other words,
Parent have one to many relationship with Child
Child have one to many relationship with Item
Parent:
- var childs : Set<Child>
Child:
- var items : Set<Item>
For storing data inside I have method :
func insert(parent : Parent) {
// remove all old Childs
parent.removeChild(Parent.childs)
for data in datas {
let child = self.newChildFromData(data)
for data2 in datas2 {
let item = self.newItemFromData2(data2)
child.addItem(item)
}
parent.addChild(child)
}
do {
try managedObjectContext.save()
} catch {
print(error.debugDescription)
}
}
NOTE This is not real code, but it is close enough to understand the problem.
When I run method for the first time (empty database), it work normal, but when I run it for the second time, it give me error
The operation couldn’t be completed. (Cocoa error 1560.)
Error Domain=NSCocoaErrorDomain Code=1560 "(null)" UserInfo={NSDetailedErrors=(
"Error Domain=NSCocoaErrorDomain Code=1570 \"The operation couldn\U2019t be completed. (Cocoa error 1570.)\" UserInfo={NSValidationErrorKey=server, NSLocalizedDescription=The operation couldn\U2019t be completed. (Cocoa error 1570.), NSValidationErrorObject...
What that could be?
If you're getting errors after changing your code to suit the two requirements try cleaning your build and delete the application from your iPhone Simulator/iPhone device. You can also refer the library Core Data Constants Reference
In addition you can also refer Core Data Model Versioning and Data Migration Programming Guide. It will help you in migrating your core data model.

Cannot Examine Function Argument via Xcode 6.4's Debug Pane

I am working with iOS 8's Core Bluetooth API. I have written some simple Swift code that creates a Central Manager and that implements the CBManager & CBPeripheral protocols. When the callbacks are executed they perform logging:
2015-09-04 14:08:33.719 CentralManager - Did update state to Powered on
2015-09-04 14:08:33.745 CentralManager - Did discover peripheral: CBPeripheral: 0x1700f5080, identifier = 3DD113C3-D175-7374-CF88- F471BB470169, name = Apple TV, state = disconnected
2015-09-04 14:08:33.955 CentralManager - Did connect peripheral: CBPeripheral: 0x1700f5080, identifier = 3DD113C3-D175-7374-CF88-F471BB470169, name = Apple TV, state = connected
2015-09-04 14:08:34.462 Peripheral - Did discover service: CBService: 0x174075600, isPrimary = YES, UUID = Continuity
2015-09-04 14:08:34.582 Peripheral: Did discover characteristic for service Continuity : ()
Everything looks good. As you can see, log statements 2 and 3 print the value of the CBPeripheral argument that was passed to the callback function. I am using Swift's string interpolation capability to accomplish this - ex. "The value is \(peripheral)".
Now for the problem: When I set a breakpoint in one of the callback functions and examine the CBPeripheral argument via Xcode's debug pane, I am not able to view any of the values that are revealed by the logging statements. When I expand the CBPeripheral (i.e. click on the triangle next to it) I see that it is a CBPeer. When I expand the CBPeer I see that it is an NSObject. But, no variables or properties are revealed.
Does anyone have an explanation for this?
Cheers, Robert

How can I re-scan for a Bluetooth LE peripheral once it disconnects from my iOS app?

I have a small iOS app that connects to a cB−OLP425i−26-A made by connectBlue.
I have it displaying the battery of the module as well as other things.
When I get too far away from the module it disconnects and I get the following error
CBUUID: E2ED3400-5650-3314-C2A8-C93508AFA475, ERROR: The connection has timed out unexpectedly.
I would like to have the app to continue to scan for the peripheral and reconnect when it gets within range. I can't seemed to be able to do this. I have tried inserting an if/else statement where as if the module is not connected a text field says "Disconnected" and if connected "Connected". Then I say if the text field says "Disconnected" the app should scan. This didn't work.
I also put into the when disconnected the [view setNeedsDisplay] and then put everything into the viewWillAppear animated Still no luck.
Can anyone explain what I should do or what I am doing wrong?
Thanks
[self stopScan] in didRetrievePeripherals
and
[central stopScan] in didConnectPeripheral
added doesn't rescan or reconnect
then added
[self startScan] in didDisconnectPeripheral
rescans and reconnects but app crashes because of
- (void)startScan
{NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:FALSE], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[manager scanForPeripheralsWithServices:self.dicoveredPeripherals options:options];
}
and
and this error message in debugger
Terminating app due to uncaught exception 'Invalid Object', reason: 'Argument E2ED3400-5650-3314-C2A8-C93508AFA475, Name = "OBP425-0B32", IsConnected = NO> is invalid'
when the app disconnects this is the whole error
Did Disconnect to peripheral: E2ED3400-5650-3314-C2A8-C93508AFA475, Name = "OBP425-0B32", IsConnected = NO> with error = The connection has timed out unexpectedly.
Can anyone help me out here?

Resources