Azure Communication Calling SDK crashes on start call - ios

I am trying to start a one on one call using Azure CommunicationCalling sdk. I am getting a crash inside one of the sdk functions as shown in screenshot for backtrace below.
Code for start call:-
func startCall(callee: String, successHandler: #escaping (Call?) -> Void ) {
// start call logic
debugPrint(callee)
let callees:[CommunicationIdentifier] = [createCommunicationIdentifier(fromRawId: callee)]
debugPrint(callees)
self.callAgent?.startCall(participants: callees, options: StartCallOptions()) { (call, error) in
if let error = error {
debugPrint(error.localizedDescription)
successHandler(nil)
} else {
self.call = call
debugPrint("call placed successfully")
successHandler(call)
}
}
}
I have verified that call agent and communication identifier arr obj passed is not nil.
Crash log:-
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
terminating with uncaught exception of type NSException
BackTrace for crash:-
I have referred to following documentation:-
https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/ui-library/get-started-composites?tabs=kotlin&pivots=platform-ios

This crash doesnt happen anymore with same sdk version. Also the beta sdk version (v2.3.0-beta.2) is working fine too.

Related

Swift: nskeyedunarchiver fails and terminates app with 'NSInvalidArgumentException', reason: '-[__NSCFData count]

NSKeyedUnarchiver.UnarchivedArrayOfObjects() terminates app with 'NSInvalidArgumentException', reason: '-[__NSCFData count]
track conforms to NSManagedObject
However decodedTrackLocation is declared #Published public var decodedTrackLocation: [CLLocation] = [], as it is not persistent, but supposed to be in memory.
The below code works on certain 'saves', but sometimes it throws an exception and I can't figure out what to do about it.
It crashes at 'if let final =' and throws this exception:
2021-06-01 17:42:28.052628+0200 GeoTrack[12300:1124356] -[__NSCFData count]: unrecognized selector sent to instance 0x17a61df50
2021-06-01 17:42:28.061055+0200 GeoTrack[12300:1124356] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData count]: unrecognized selector sent to instance 0x17a61df50'
*** First throw call stack:
(0x1a9e27298 0x1bdb81480 0x1a9d362a8 0x1a9e298f4 0x1a9e2b89c 0x1ad67168c 0x1ad707e24 0x1026e5988 0x102704310 0x1b0345f94 0x1b0345fb0 0x1b0345f94 0x1b0737d74 0x1b0733e68 0x1b02225f4 0x1b088b190 0x1031f7ae8 0x102ee7ae8 0x102ee932c 0x102ef776c 0x1a9da62e0 0x1a9da0740 0x1a9d9f818 0x1c04a5570 0x1ac6cb0e8 0x1ac6d0664 0x1025696dc 0x1a9a7e140)
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData count]: unrecognized selector sent to instance 0x17a61df50'
terminating with uncaught exception of type NSException
The reason the NSKeyedUnarchiver fails is because I did something stupid, I stored the wrong Data. What I can't grasp is why the do-try-catch block this code lives in, doesn't work/catch.
Any help would be appreciated.
The code in Question:
do{
let out = try Data(referencing: NSData(data: track.trackLocation).decompressed(using: .lzma))
let archiver = try NSKeyedUnarchiver(forReadingFrom: out)
archiver.requiresSecureCoding = true
archiver.decodingFailurePolicy = .setErrorAndReturn
if let final = archiver.decodeArrayOfObjects(ofClass: CLLocation.self, forKey: NSKeyedArchiveRootObjectKey){
track.decodedTrackLocation = final
}
} catch {
print(error)
}
do{
let out = try Data(referencing: NSData(data: track.trackLocation).decompressed(using: .lzma))
if let final = try NSKeyedUnarchiver.unarchivedArrayOfObjects(ofClass: CLLocation.self, from: out){
track.decodedTrackLocation = final
}
} catch {
print(error)
}
Because it's not an Error that is thrown (throws), it's a NSInvalidArgumentException, a NSException, on Objective-C one. You can look for it :) - Larme
I learned something new!

Having an error when fetching request of Core Data

I want to store some new data in core data. Most of the times it works, but it gives an error of
[error] error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. *** Collection <__NSCFSet: 0x16eb6a50> was mutated while being enumerated. with userInfo (null)
CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. *** Collection <__NSCFSet: 0x16eb6a50> was mutated while being enumerated. with userInfo (null)
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSCFSet: 0x16eb6a50> was mutated while being enumerated.'
*** First throw call stack:
(0x1deefb3d 0x1d177067 0x1deef5e1 0x1fea4bbb 0x1fe8a863 0x1fe89be5 0x1fe68da9 0x9403ec 0x8cefc 0x137ed0 0x134530 0x13790c 0x126ab0 0xd0be0 0xd3a467 0xd3a453 0xd3ed47 0x1deabd69 0x1dea9e19 0x1ddfd1af 0x1ddfcfd1 0x1f5a7b41 0x2317fa53 0x8e068 0x1d5ea4eb)
libc++abi.dylib: terminating with uncaught exception of type NSException
occasionally.
Here are the codes of getData in AppDelegate
func getData(request: NSFetchRequest<NSManagedObject>) -> Any{
do {
let context = persistentContainer.viewContext
let results = try context.fetch(request)
return results
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
I discovered that it breaks at let results = try context.fetch(request). I wonder if there is any problem with this line or other lines?
Does anyone have any ideas? Thanks in advance

import AlgoliaSearch with Swift 2 causing error

Adding this line to my App import AlgoliaSearch returns this error:
2017-05-08 22:35:07.814593 XXXXXX[6255:2627487] -[__NSDictionaryI
length]: unrecognized selector sent to instance 0x1702f0980 2017-05-08
22:35:07.816565 XXXXXX[6255:2627487] * Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason:
'-[__NSDictionaryI length]: unrecognized selector sent to instance
0x1702f0980'
* First throw call stack: (0x192f351b8 0x19196c55c 0x192f3c268 0x192f39270 0x192e3280c 0x1015c8608 0x10158d72c 0x10194a198
0x1001f6c24 0x1001f8c9c 0x100091fd4 0x1003973d4 0x100397690
0x1003be2c0 0x101a5d258 0x101a5d218 0x101a62280 0x192ee2810
0x192ee03fc 0x192e0e2b8 0x1948c2198 0x198e557fc 0x198e50534
0x10013c734 0x191df15b8) libc++abi.dylib: terminating with uncaught
exception of type NSException (lldb)
The line of code it is referring to is as below:
self.ref.child("users").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
for user in snapshot.children{
var numVids = NSDictionary()
if ((user.hasChild("videos")) == true){
--> numVids = user.value["videos"] as! NSDictionary
}
}
As soon as I remove the import Algolia module the error is removed, I have tried changing the version of the module and even switching to use the objc version but the error was the same.
Anyone seen something like this before?
https://github.com/algolia/algoliasearch-client-swift
https://github.com/algolia/algoliasearch-client-objc

Catching NSJSONSerialization errors in Swift

I'm trying to understand why I'm unable to catch the errors thrown by NSJSONSerialization.
I expect the NSInvalidArgumentException exception to be raised and caught, but instead the app crashes.
This is occurring in both Swift 3 and Swift 2.3 using Xcode 8.
Swift 3:
do {
_ = try JSONSerialization.data(withJSONObject: ["bad input" : NSDate()])
}
catch {
print("this does not print")
}
Swift 2.3:
do {
_ = try NSJSONSerialization.dataWithJSONObject(["bad input" : NSDate()], options: NSJSONWritingOptions())
}
catch {
print("this does not print")
}
This code is put in applicationDidFinishLaunching inside a blank Xcode project. Tested on both simulator and device.
Full exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__NSDate)'
Any ideas why the catch block is not catching this particular error?
From the documentation for JSONSerialization data(withJSONObject:options:):
If obj will not produce valid JSON, an exception is thrown. This exception is thrown prior to parsing and represents a programming error, not an internal error. You should check whether the input will produce valid JSON before calling this method by using isValidJSONObject(_:).
What this means is that you can't catch the exception caused by invalid data. Only "internal errors" (whatever that actually means) can be caught in the catch block.
To avoid a possible NSInvalidArgumentException you need to use isValidJSONObject.
Your code then becomes:
do {
let obj = ["bad input" : NSDate()]
if JSONSerialization.isValidJSONObject(obj) {
_ = try JSONSerialization.data(withJSONObject: obj)
} else {
// not valid - do something appropriate
}
}
catch {
print("Some vague internal error: \(error)")
}

CKModifyBadgeOperation crashes for no reason

I have created a subscription for insert & it sends push notification as follows
let subscriptionNotification = CKNotificationInfo()
subscriptionNotification.alertBody = "New Book has been created by Author"
subscriptionNotification.shouldBadge = true
subscription.notificationInfo = subscriptionNotification
When I receive the notification I open the app & I am simply trying to reset badge to zero
let resetBadge = CKModifyBadgeOperation(badgeValue: 0)
resetBadge.modifyBadgeCompletionBlock = {(error) in
if error != nil {
print(error)
}
else {
application.applicationIconBadgeNumber = 0
}
}
CKContainer.defaultContainer().addOperation(resetBadge)
I run this code on appdelegate did finish launching with options method.
I get following error. Keep in mind the name of the project is ckreference demo.
2015-12-15 21:41:58.417 ckreference demo[2486:1478837] -[CKNotification queryNotificationReason]: unrecognized selector sent to instance 0x15cd8a960
2015-12-15 21:41:58.427 ckreference demo[2486:1478837] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CKNotification queryNotificationReason]: unrecognized selector sent to instance 0x15cd8a960'
* First throw call stack:
(0x183521900 0x182b8ff80 0x18352861c 0x1835255b8 0x18342968c 0x1000b8b9c 0x1000b9250 0x1884cbae4 0x1884b9de0 0x184ad7790 0x184ad7b10 0x1834d8efc 0x1834d8990 0x1834d6690 0x183405680 0x184914088 0x18827cd90 0x1000b94d0 0x182fa68b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
Any suggestions on how to stop app from crashing?
The crash happens here

Resources