Crash while using CFHostCreateWithName: "Attempt to start the Thread again" - ios

help!
I met a crash when i try to get the addresses for the give hostname;
the crash log shows like this:
1 libobjc.A.dylib 0x0000000197d180e4 objc_exception_throw + 56
2 CoreFoundation 0x0000000186044218 -[NSException initWithCoder:]
3 Foundation 0x0000000186e9528c -[NSThread start] + 136
4 ZFirewall7.dylib 0x0000000105e4d768 -[FiPSettingsManager doHostStuff:] + 1124
5 ZFirewall7.dylib 0x0000000105e48424 _ZL23my_CFHostCreateWithNamePPK13__CFAllocatorPPK10__CFString + 164
6 Upload 0x000000010220d1c0 +[UploadUtil addressesForHostname:] (UploadUtil.m:277)
7 Upload 0x000000010220d120 +[UploadUtil addressForHostname:] (UploadUtil.m:267)
....
*** -[NSThread start]: attempt to start the thread again
and my code is:
+(NSArray *)addressesForHostname:(NSString *)hostname
{
// Get the addresses for the given hostname.
CFHostRef hostRef = CFHostCreateWithName(kCFAllocatorDefault, (__bridge CFStringRef)hostname);
BOOL isSuccess = CFHostStartInfoResolution(hostRef, kCFHostAddresses, nil);
if (!isSuccess)
{
CFRelease(hostRef);
return nil;
}
CFArrayRef addressesRef = CFHostGetAddressing(hostRef, nil);
if (addressesRef == nil)
{
CFRelease(hostRef);
return nil;
}
// Convert these addresses into strings.
char ipAddress[INET6_ADDRSTRLEN];
NSMutableArray *addresses = [NSMutableArray array];
CFIndex numAddresses = CFArrayGetCount(addressesRef);
for (CFIndex currentIndex = 0; currentIndex < numAddresses; currentIndex++) {
struct sockaddr *address = (struct sockaddr *)CFDataGetBytePtr(CFArrayGetValueAtIndex(addressesRef, currentIndex));
if (address == nil)
{
CFRelease(hostRef);
return nil;
}
getnameinfo(address, address->sa_len, ipAddress, INET6_ADDRSTRLEN, nil, 0, NI_NUMERICHOST);
[addresses addObject:[NSString stringWithCString:ipAddress encoding:NSASCIIStringEncoding]];
}
CFRelease(hostRef);
return addresses;
}
this function do called by several threads, and the doc of CFHostCreateWithName says that it is thread safe, now i have no idea about how to solve this problem.
help!

Related

iOS crash using dispatch_sync

In my iOS app I read a large CSV file and load it (via inserts) in a SQLite database.
This is my code:
- (void) parseCSVFile:(NSString *)path
{
__block BOOL isFileOk = NO;
__block BOOL atLeastOneRowProcessed = NO;
NSFileManager *fileMgr = [[NSFileManager alloc] init];
unsigned long totalSize = [[[fileMgr attributesOfItemAtPath:path error:nil] objectForKey:#"NSFileSize"] intValue];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:#"mydatabase.sqlite"];
const char *dbpath = [writableDBPath UTF8String];
dispatch_queue_t databaseQueue = [(AppDelegate *)[[UIApplication sharedApplication] delegate] databaseQueue];
dispatch_sync(databaseQueue, ^{
sqlite3 *ddbb;
NSLog(#"INIT DATABASE");
if (sqlite3_open(dbpath, &ddbb) == SQLITE_OK)
{
char* errorMessage;
sqlite3_exec(ddbb, "DROP TABLE IF EXISTS datainfile", NULL, NULL, &errorMessage);
sqlite3_exec(ddbb, "CREATE TABLE \"datainfile\" (\"field1\" TEXT PRIMARY KEY NOT NULL ,\"field2\" TEXT DEFAULT (null) ,\"field3\" TEXT DEFAULT (null) ,\"field4\" TEXT)", NULL, NULL, &errorMessage);
sqlite3_exec(ddbb, "BEGIN TRANSACTION", NULL, NULL, &errorMessage);
char buffer[] = "INSERT OR IGNORE INTO datainfile VALUES (?1, ?2, ?3, ?4)";
sqlite3_stmt* stmt;
sqlite3_prepare_v2(ddbb, buffer, (int)strlen(buffer), &stmt, NULL);
char *pathUTF8 = (char*)[path UTF8String];
FILE* stream = fopen(pathUTF8, "r");
char *field1 = "";
char *field2 = "";
char *field3 = "";
char *field4 = "";
NSLog(#"READING FILE");
unsigned long processedSize = 0;
char line[1024];
while(fgets(line, 1024, stream))
{
processedSize = processedSize + strlen(line) * sizeof(char);
char* tmp = strdup(line);
field1 = strtok (tmp,", \t");
field2 = strtok (NULL, ", \t");
field3 = strtok (NULL, ", \t");
field4 = strtok (NULL, "\r\n");
atLeastOneRowProcessed = YES;
if(!isFileOk)
{
isFileOk = [self checkIfFileIsACorrectCSVWithField1:field1 field2:field2 field3:field3 andField4:field4];
if(!isFileOk)
{
if([_delegate respondsToSelector:#selector(fileParserError:)])
[_delegate fileParserError:_reportErrorMessage];
free(tmp);
break;
}
}
sqlite3_bind_text(stmt, 1, field1, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 2, field2, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 3, field3, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 4, field4, -1, SQLITE_STATIC);
if (sqlite3_step(stmt) != SQLITE_DONE)
{
NSLog(#"ERROR: Commit Failed in line %s!\n", line);
// If there was an error we try to repeat the commit
sqlite3_reset(stmt);
sqlite3_bind_text(stmt, 1, field1, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 2, field2, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 3, field3, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 4, field4, -1, SQLITE_STATIC);
if (sqlite3_step(stmt) != SQLITE_DONE)
{
NSLog(#"ERROR: Commit failed again");
}
else
{
NSLog(#"ERROR: Commit success");
}
}
sqlite3_reset(stmt);
free(tmp);
}
if(isFileOk)
{
NSLog(#"File read and now the commit starts");
sqlite3_exec(ddbb, "COMMIT TRANSACTION", NULL, NULL, &errorMessage);
_phase = PARSER_PHASE_CREATING_INDEX;
sqlite3_exec(ddbb, "CREATE INDEX field1 ON datainfile(field1);", NULL, NULL, &errorMessage);
sqlite3_finalize(stmt);
NSLog(#"Commit has ended");
}
}
sqlite3_close(ddbb);
});
if(isFileOk)
{
if([_delegate respondsToSelector:#selector(fileParserFinished)])
[_delegate fileParserFinished];
}
else
{
if(!atLeastOneRowProcessed)
{
_reportErrorMessage = NSLocalizedString(#"TXT_FILEERROR_NOPROCESSED", Nil);
if([_delegate respondsToSelector:#selector(fileParserError:)])
[_delegate fileParserError:_reportErrorMessage];
}
}
}
databaseQueue is an attribute of AppDelegate created this way:
_databaseQueue = dispatch_queue_create("com.mycompany.myapp.database", 0);
Well, this is working well almost always. But sometimes it happens a strange crash. This is the log:
Crashed: com.mycompany.myapp.database
0 libsystem_kernel.dylib 0x1865d1014 __pthread_kill + 8
1 libsystem_pthread.dylib 0x18669b264 pthread_kill + 112
2 libsystem_c.dylib 0x1865459c4 abort + 140
3 libsystem_c.dylib 0x186545ad8 _UTF2_init + 82
4 libsystem_c.dylib 0x186559c7c __chk_fail_overlap + 54
5 libsystem_c.dylib 0x186559c44 __chk_fail + 18
6 libsystem_c.dylib 0x18655a04c __vsprintf_chk + 134
7 MyApp 0x1000c151c __32-[FileParser parseCSVFile:]_block_invoke (FileParser.m:650)
8 libdispatch.dylib 0x18648e9a0 _dispatch_client_callout + 16
9 libdispatch.dylib 0x18649bee0 _dispatch_barrier_sync_f_invoke + 84
10 MyApp 0x1000c1084 -[FileParser parseCSVFile:] (FileParser.m:734)
11 MyApp 0x1000bed28 -[FileParser readFileWithPath:andDelegate:] (FileParser.m:147)
12 MyApp 0x100041a64 __57-[HomeViewController readFileWithPath:]_block_invoke_2 (HomeViewController.m:625)
13 libdispatch.dylib 0x18648e9e0 _dispatch_call_block_and_release + 24
14 libdispatch.dylib 0x18648e9a0 _dispatch_client_callout + 16
15 libdispatch.dylib 0x18649d0d4 _dispatch_queue_override_invoke + 644
16 libdispatch.dylib 0x18649ea50 _dispatch_root_queue_drain + 540
17 libdispatch.dylib 0x18649e7d0 _dispatch_worker_thread3 + 124
18 libsystem_pthread.dylib 0x186697100 _pthread_wqthread + 1096
19 libsystem_pthread.dylib 0x186696cac start_wqthread + 4
It happens in the lines 734 and 650 of my FileParser, and these lines are:
(line 734) the second if(isFileOk)
Just the first line after leaving the dispatch_sync.
(line 650) processedSize = processedSize + strlen(line) * sizeof(char);
Reading the first line of the CSV file.
It seems to me like the dispatch_sync leaves its code before it's executed, calling "simultaneously" a line outside the block and one line inside the block.
I must add that when this crash has happened the line that crashed outside the block is always if(isFileOk), but the line that crashed inside the block varies.
What could it be happening?

CoreTelephony crash for reason: Received a notification with no notification name

I receive about 5,000 reported issue for reason "Received a notification with no notification name" everyday.
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException' reason: 'Received a notification with no notification name'
Last Exception Backtrace:
0 CoreFoundation 0x000000018206e950 __exceptionPreprocess + 132
1 libobjc.A.dylib 0x000000018e5741fc objc_exception_throw + 60
2 CoreFoundation 0x000000018206e810 +[NSException raise:format:arguments:] + 116
3 Foundation 0x0000000182ba6db4 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 112
4 CoreTelephony 0x00000001827ca39c -[CTTelephonyNetworkInfo handleNotificationFromConnection:ofType:withInfo:] + 272
5 CoreTelephony 0x00000001827c9784 _ServerConnectionCallback(__CTServerConnection*, __CFString const*, __CFDictionary const*, void*) + 152
6 CoreTelephony 0x00000001827de958 ___ZNK13CTServerState21sendNotification_syncE7CTEventPK10__CFStringPK14__CFDictionary_block_invoke15 + 32
7 libdispatch.dylib 0x000000018eb4c014 _dispatch_call_block_and_release + 24
8 libdispatch.dylib 0x000000018eb4bfd4 _dispatch_client_callout + 16
9 libdispatch.dylib 0x000000018eb524a8 _dispatch_queue_drain + 640
10 libdispatch.dylib 0x000000018eb4e4c0 _dispatch_queue_invoke + 68
11 libdispatch.dylib 0x000000018eb530f4 _dispatch_root_queue_drain + 104
12 libdispatch.dylib 0x000000018eb534fc _dispatch_worker_thread2 + 76
13 libsystem_pthread.dylib 0x000000018ece16bc _pthread_wqthread + 356
14 libsystem_pthread.dylib 0x000000018ece154c start_wqthread + 4
I found all CoreTelephony notification and tried to reproduce the issue but failed.
/* For use with the CoreTelephony notification system. */
extern CFStringRef kCTRegistrationStatusChangedNotification;
extern CFStringRef kCTRegistrationStateDurationReportNotification;
extern CFStringRef kCTRegistrationServiceProviderNameChangedNotification;
extern CFStringRef kCTRegistrationOperatorNameChangedNotification;
extern CFStringRef kCTRegistrationNewServingNetworkNotification;
extern CFStringRef kCTRegistrationDataStatusChangedNotification;
extern CFStringRef kCTRegistrationDataActivateFailedNotification;
extern CFStringRef kCTRegistrationCellularDataPlanHideIndicatorNotification;
extern CFStringRef kCTRegistrationCellularDataPlanActivateFailedNotification;
extern CFStringRef kCTRegistrationCustomerServiceProfileUpdateNotification;
extern CFStringRef kCTRegistrationCellChangedNotification;
extern CFStringRef kCTRegistrationCauseCodeNotification;
Why do I get this crash?
And how can I change my code so that I do not get this issue anymore?
Any help is highly appreciated.
EDIT:
I am using Reachability class (https://github.com/tonymillion/Reachability) to detect network type.
+ (NSString *)networkName
{
Reachability *reach = [Reachability reachabilityForInternetConnection];
[reach startNotifier];
NetworkStatus networkStatus = [reach currentReachabilityStatus];
CTTelephonyNetworkInfo *telephonyInfo = [[CTTelephonyNetworkInfo alloc] init];
if (networkStatus == ReachableViaWiFi) {
return #"WIFI";
} else if (networkStatus == ReachableViaWWAN) {
if ([telephonyInfo respondsToSelector:#selector(currentRadioAccessTechnology)]) {
if ([[telephonyInfo currentRadioAccessTechnology] isEqualToString:CTRadioAccessTechnologyGPRS]) {
return #"GPRS";
} else if ([[telephonyInfo currentRadioAccessTechnology] isEqualToString:CTRadioAccessTechnologyEdge]) {
return #"EDGE";
} else if ([[telephonyInfo currentRadioAccessTechnology] isEqualToString:CTRadioAccessTechnologyWCDMA]) {
return #"WCDMA";
} else if ([[telephonyInfo currentRadioAccessTechnology] isEqualToString:CTRadioAccessTechnologyHSDPA]) {
return #"HSDPA";
} else if ([[telephonyInfo currentRadioAccessTechnology] isEqualToString:CTRadioAccessTechnologyHSUPA]) {
return #"HSUPA";
} else if ([[telephonyInfo currentRadioAccessTechnology] isEqualToString:CTRadioAccessTechnologyCDMA1x]) {
return #"CDMA1X";
} else if ([[telephonyInfo currentRadioAccessTechnology] isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]) {
return #"CDMAEVDOREV0";
} else if ([[telephonyInfo currentRadioAccessTechnology] isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]) {
return #"CDMAEVDOREVA";
} else if ([[telephonyInfo currentRadioAccessTechnology] isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]) {
return #"CDMAEVDOREVB";
} else if ([[telephonyInfo currentRadioAccessTechnology] isEqualToString:CTRadioAccessTechnologyeHRPD]) {
return #"HRPD";
} else if ([[telephonyInfo currentRadioAccessTechnology] isEqualToString:CTRadioAccessTechnologyLTE]) {
return #"LTE";
}
return #"UNKNOWN";
} else {
return #"WWAN";
}
} else {
return #"NotReachable";
}
}
I wonder if this is related to this similar issue with the old version of TestFlight:
There is an iOS bug that causes instances of the CTTelephonyNetworkInfo class to sometimes get notifications after they have been deallocated. Instead of instantiating, using, and releasing instances you must instead retain and never release them to work around the bug.
This smells like a zombie from the looks of your backtrace. Why not try using a static instance of CTTelephonyNetworkInfo that is never released as suggested in the linked question?
#import CoreTelephony;
// ...
static CTTelephonyNetworkInfo *netInfo;
static dispatch_once_t dispatchToken;
if (!netInfo) {
dispatch_once(&dispatchToken, ^{
netInfo = [[CTTelephonyNetworkInfo alloc] init];
});
}
To fix this issue, I use method swizzling to re-routing all calls that were originally sent to -[CTTelephonyNetworkInfo handleNotificationFromConnection:ofType:withInfo:] .
It works fine.
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
struct __CTServerConnection {
int a;
int b;
CFMachPortRef myport;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
};
typedef struct __CTServerConnection CTServerConnection;
typedef CTServerConnection* CTServerConnectionRef;
#implementation CTTelephonyNetworkInfo (Fixed)
- (void)fixed_handleNotificationFromConnection:(CTServerConnectionRef)connection
ofType:(NSString *)notificationName
withInfo:(NSDictionary *)info
{
if ([notificationName length]) {
return [self fixed_handleNotificationFromConnection:connection
ofType:notificationName
withInfo:info];
}
}

Obj-C: Application crashing while converting NSDictionary to JSON

I am reading safari's Bookmarks.plist and storing it in an NSDictionary then trying to convert the NSDictionary into JSON
Problem
Bookmarks data is getting into dictionary but when I am converting the data into JSON the application is crashing.
NSString* path = #"path of the plist file";
NSDictionary *plistDict = [NSDictionary dictionaryWithContentsOfFile:path];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:plistDict
options:NSJSONWritingPrettyPrinted error:&error];
NSString* result = [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding];
Reason
The NSDictonary made of the Plist file contains some fields that are the type of NSData. Is there a way to convert all NSData fields to Base64 string in order clean the NSDictionary? Note that it is not possible to be aware of what fields and how many fields are type of NSData beforehand.
ErrorLog
2016-04-12 14:44:13.560 plistTOjosn[4228:68289] An uncaught exception was raised
2016-04-12 14:44:13.560 plistTOjosn[4228:68289] Invalid type in JSON write (__NSCFData)
2016-04-12 14:44:13.561 plistTOjosn[4228:68289] (
0 CoreFoundation 0x00007fff92d9b03c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff914e176e objc_exception_throw + 43
2 CoreFoundation 0x00007fff92d9aeed +[NSException raise:format:] + 205
3 Foundation 0x00007fff91174b9a _writeJSONValue + 715
4 Foundation 0x00007fff91175cef ___writeJSONObject_block_invoke + 220
5 CoreFoundation 0x00007fff92d9a65c ____NSDictionaryEnumerate_block_invoke439 + 28
6 CoreFoundation 0x00007fff92c7b0b0 CFBasicHashApply + 128
7 CoreFoundation 0x00007fff92cbc118 __NSDictionaryEnumerate + 664
8 Foundation 0x00007fff91175b1f _writeJSONObject + 439
9 Foundation 0x00007fff91174ab6 _writeJSONValue + 487
10 Foundation 0x00007fff91175cef ___writeJSONObject_block_invoke + 220
11 CoreFoundation 0x00007fff92d9a65c ____NSDictionaryEnumerate_block_invoke439 + 28
12 CoreFoundation 0x00007fff92c7b0b0 CFBasicHashApply + 128
13 CoreFoundation 0x00007fff92cbc118 __NSDictionaryEnumerate + 664
14 Foundation 0x00007fff91175b1f _writeJSONObject + 439
15 Foundation 0x00007fff91174ab6 _writeJSONValue + 487
16 Foundation 0x00007fff9117489a -[_NSJSONWriter dataWithRootObject:options:error:] + 137
17 Foundation 0x00007fff91174765 +[NSJSONSerialization dataWithJSONObject:options:error:] + 345
18 Utilities 0x00000001000c7d0b -[BrowserJunkUtilities readPlistFileFromSafariProfiles:] + 331
19 Utilities 0x00000001000c7e4b -[BrowserJunkUtilities safariBookmarksJson] + 59
20 Utilities 0x00000001000bbd5c -[BrowserJunkUtilities LogInBigData] + 252
21 Utilities 0x00000001000c1af2 -[BrowserJunkUtilities init] + 5970
22 plistTOjosn 0x00000001000299e5 -[DashBoardView init] + 261
23 plistTOjosn 0x0000000100016e45 -[AppController changeViewController:RunFix:] + 757
24 plistTOjosn 0x0000000100018fe5 -[AppController showIntroView:tag:] + 181
25 plistTOjosn 0x0000000100016a7f -[AppController awakeFromNib] + 1103
26 CoreFoundation 0x00007fff92ca7bdf -[NSSet makeObjectsPerformSelector:] + 223
27 AppKit 0x00007fff9329e03d -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1216
28 AppKit 0x00007fff9327d0e5 loadNib + 384
29 AppKit 0x00007fff9327c60b +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 313
30 AppKit 0x00007fff9327c3c7 -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 201
31 AppKit 0x00007fff9327c193 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 344
32 AppKit 0x00007fff93274d79 NSApplicationMain + 605
33 plistTOjosn 0x0000000100007542 main + 34
34 plistTOjosn 0x00000001000016d4 start + 52
35 ??? 0x0000000000000003 0x0 + 3
)
2016-04-12 14:44:13.690 plistTOjosn[4228:68289] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__NSCFData)'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff92d9b03c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff914e176e objc_exception_throw + 43
2 CoreFoundation 0x00007fff92d9aeed +[NSException raise:format:] + 205
3 Foundation 0x00007fff91174b9a _writeJSONValue + 715
4 Foundation 0x00007fff91175cef ___writeJSONObject_block_invoke + 220
5 CoreFoundation 0x00007fff92d9a65c ____NSDictionaryEnumerate_block_invoke439 + 28
6 CoreFoundation 0x00007fff92c7b0b0 CFBasicHashApply + 128
7 CoreFoundation 0x00007fff92cbc118 __NSDictionaryEnumerate + 664
8 Foundation 0x00007fff91175b1f _writeJSONObject + 439
9 Foundation 0x00007fff91174ab6 _writeJSONValue + 487
10 Foundation 0x00007fff91175cef ___writeJSONObject_block_invoke + 220
11 CoreFoundation 0x00007fff92d9a65c ____NSDictionaryEnumerate_block_invoke439 + 28
12 CoreFoundation 0x00007fff92c7b0b0 CFBasicHashApply + 128
13 CoreFoundation 0x00007fff92cbc118 __NSDictionaryEnumerate + 664
14 Foundation 0x00007fff91175b1f _writeJSONObject + 439
15 Foundation 0x00007fff91174ab6 _writeJSONValue + 487
16 Foundation 0x00007fff9117489a -[_NSJSONWriter dataWithRootObject:options:error:] + 137
17 Foundation 0x00007fff91174765 +[NSJSONSerialization dataWithJSONObject:options:error:] + 345
18 Utilities 0x00000001000c7d0b -[BrowserJunkUtilities readPlistFileFromSafariProfiles:] + 331
19 Utilities 0x00000001000c7e4b -[BrowserJunkUtilities safariBookmarksJson] + 59
20 Utilities 0x00000001000bbd5c -[BrowserJunkUtilities LogInBigData] + 252
21 Utilities 0x00000001000c1af2 -[BrowserJunkUtilities init] + 5970
22 plistTOjosn 0x00000001000299e5 -[DashBoardView init] + 261
23 plistTOjosn 0x0000000100016e45 -[AppController changeViewController:RunFix:] + 757
24 plistTOjosn 0x0000000100018fe5 -[AppController showIntroView:tag:] + 181
25 plistTOjosn 0x0000000100016a7f -[AppController awakeFromNib] + 1103
26 CoreFoundation 0x00007fff92ca7bdf -[NSSet makeObjectsPerformSelector:] + 223
27 AppKit 0x00007fff9329e03d -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1216
28 AppKit 0x00007fff9327d0e5 loadNib + 384
29 AppKit 0x00007fff9327c60b +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 313
30 AppKit 0x00007fff9327c3c7 -[NSBundle(NSNibLoadin
g) loadNibNamed:owner:topLevelObjects:] + 201
31 AppKit 0x00007fff9327c193 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 344
32 AppKit 0x00007fff93274d79 NSApplicationMain + 605
33 plistTOjosn 0x0000000100007542 main + 34
34 plistTOjosn 0x00000001000016d4 start + 52
35 ??? 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException
PLIST DATA
{
Children = (
{
Title = History;
WebBookmarkIdentifier = History;
WebBookmarkType = WebBookmarkTypeProxy;
WebBookmarkUUID = "019DBF83-1882-46AA-A8A7-669CCD3D5AB8";
},
{
Children = (
{
Sync = {
Key = "\"C=32#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/63582BD8-0400-40C4-9CA7-8942391957B8.xbel";
};
URIDictionary = {
title = "vikas Technologies Pvt. Ltd Mail";
};
URLString = "https://mail.google.com/mail/u/0/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "AFDCB7C0-10CE-4273-BDF8-E2FC40D83A3A";
},
{
Sync = {
Key = "\"C=6#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/474F816C-BB3E-4F42-89B4-666F5E323840.xbel";
};
URIDictionary = {
title = Apple;
};
URLString = "https://www.apple.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "4468D8F5-6A99-4B0A-85AD-E1E49B58546D";
},
{
Sync = {
Key = "\"C=8#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/89401E9C-92BB-4935-91D1-F968FD90239B.xbel";
};
URIDictionary = {
title = iCloud;
};
URLString = "https://www.icloud.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "2E4E8D77-D2C4-4B79-A563-5FF5FED0D553";
},
{
Sync = {
Key = "\"C=10#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/6B14FBB9-DA11-4F5B-BF85-4E997D73C720.xbel";
};
URIDictionary = {
title = Yahoo;
};
URLString = "https://www.yahoo.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "9CFD581F-2404-4BDF-8795-5D4DCC9A7CF0";
},
{
Sync = {
Key = "\"C=12#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/0F0130B7-2F0C-4BD5-9173-E91C210F845C.xbel";
};
URIDictionary = {
title = Bing;
};
URLString = "https://www.bing.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "89FEEC32-AC16-4A80-8875-68BE4A191862";
},
{
Sync = {
Key = "\"C=14#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/9554C3E5-61CD-40BE-BFB2-7FBEB22807C0.xbel";
};
URIDictionary = {
title = Google;
};
URLString = "https://www.google.com/?client=safari&channel=mac_bm";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "5A013EF2-E017-41B3-8FAE-2DA718D35AC5";
},
{
Sync = {
Key = "\"C=16#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/56EA5315-E1B1-430B-A018-7326A247ECAA.xbel";
};
URIDictionary = {
title = Wikipedia;
};
URLString = "https://www.wikipedia.org/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "49CE5DC7-6ABD-4876-95E4-0C7A007DED0D";
},
{
Sync = {
Key = "\"C=18#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/FDF4AD0D-FD33-4EE2-9097-19CA5046AFB7.xbel";
};
URIDictionary = {
title = Facebook;
};
URLString = "https://www.facebook.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "530A47C6-D116-4081-9BED-3C469C7C7697";
},
{
Sync = {
Key = "\"C=20#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/3E61C9CF-7646-4475-AC89-FB157DA50181.xbel";
};
URIDictionary = {
title = Twitter;
};
URLString = "https://twitter.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "D3893EF3-A885-41F6-A128-BBAC37A2033B";
},
{
Sync = {
Key = "\"C=22#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/C8801D19-7A76-4290-8950-5DA9385F3415.xbel";
};
URIDictionary = {
title = LinkedIn;
};
URLString = "https://www.linkedin.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "47F6045D-4F9A-4856-916A-07CB8889B7E2";
},
{
Sync = {
Key = "\"C=24#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/DF10E9C3-01FA-4EC6-ADE2-4A0B1FECD9EF.xbel";
};
URIDictionary = {
title = "The Weather Channel";
};
URLString = "http://www.weather.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "0DDD3778-437A-4FAE-8529-D389A5122758";
},
{
Sync = {
Key = "\"C=26#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/79C2C180-430C-4092-A4CF-D2B8F4551B1E.xbel";
};
URIDictionary = {
title = Yelp;
};
URLString = "http://www.yelp.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "2FD1AB60-B3A0-44D5-A20D-68CF51A40584";
},
{
Sync = {
Key = "\"C=28#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/63EDC45D-3138-41CF-A617-4178097656F0.xbel";
};
URIDictionary = {
title = TripAdvisor;
};
URLString = "http://www.tripadvisor.com/";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "A6DA8288-409E-4B03-84E4-ACEF9F2B624C";
},
{
Sync = {
Key = "\"C=30#U=19016305-56c9-437c-95f4-93521bad2be8\"";
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/40F8D2AF-4F2E-44BE-8250-41E1C7C0F1D9.xbel";
};
URIDictionary = {
title = "ADplus.aspx";
};
URLString = "http://dev.etelmar.net/ADEV_ADplus3-01/ADplus.aspx";
WebBookmarkType = WebBookmarkTypeLeaf;
WebBookmarkUUID = "C5D3ADD4-DB17-421D-BAF5-04927F713BCE";
}
);
Sync = {
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/2A662FEA-35F9-44C5-87B9-8DDEBE0E4912/";
};
Title = BookmarksBar;
WebBookmarkType = WebBookmarkTypeList;
WebBookmarkUUID = "E2EC6281-F0F9-41FA-9C2C-2DC8745F547A";
},
{
Sync = {
ServerID = "https://bnslvks%40icloud.com#p35-bookmarks.icloud.com/8402630368/bookmarks/C81C19F2-E6A6-46C7-9836-DC58A02B46AB/";
};
Title = BookmarksMenu;
WebBookmarkType = WebBookmarkTypeList;
WebBookmarkUUID = "06621BC7-DAA3-4225-8BCB-A65A8E0D0916";
}
);
Sync = {
ServerData = <62706c69 73743030 de010203 04050607 08090a0b 0c0d0e0f 10111213 14151624 25303120 20545054 61675443 54616757 50757368 4b65795d 426f6f6b 6d61726b 42617249 645d486f 6d655552 4c537472 696e675e 426f6f6b 6d61726b 4d656e75 49645c41 63636f75 6e745072 7349645c 42756c6b 52657175 65737473 5953796e 63546f6b 656e5e50 75736854 72616e73 706f7274 735d436c 69656e74 56657273 696f6e5f 10125072 696e6369 70616c55 524c5374 72696e67 5f101653 7570706f 72747353 796e6343 6f6c6c65 6374696f 6e5f100f 496e6974 69616c53 796e6344 6f6e655f 10195365 72766572 446f6573 4e6f7453 7570706f 72745054 6167735f 10314654 3d2d4052 553d3139 30313633 30352d35 3663392d 34333763 2d393566 342d3933 35323162 61643262 65384053 3d33315a 38343032 36333033 36385f10 72687474 70733a2f 2f62616e 73616c76 6b732534 3069636c 6f75642e 636f6d40 7033352d 626f6f6b 6d61726b 732e6963 6c6f7564 2e636f6d 2f383430 32363330 3336382f 626f6f6b 6d61726b 732f3241 36363246 45412d33 3546392d 34344335 2d383742 392d3844 44454245 30453439 31322f5f 104d6874 7470733a 2f2f6261 6e73616c 766b7325 34306963 6c6f7564 2e636f6d 40703335 2d626f6f 6b6d6172 6b732e69 636c6f75 642e636f 6d2f3834 30323633 30333638 2f626f6f 6b6d6172 6b732f5f 10726874 7470733a 2f2f6261 6e73616c 766b7325 34306963 6c6f7564 2e636f6d 40703335 2d626f6f 6b6d6172 6b732e69 636c6f75 642e636f 6d2f3834 30323633 30333638 2f626f6f 6b6d6172 6b732f43 38314331 3946322d 45364136 2d343643 372d3938 33362d44 43353841 30324234 3641422f 5a383430 32363330 333638d2 17181922 54637275 64567369 6d706c65 d41a1b1c 1d1e1f20 20586d61 782d7369 7a655d6d 61782d72 65736f75 72636573 56757064 61746556 696e7365 72741200 a0000010 c80909d3 1b1d1a1f 201e095f 103e4441 5653542d 56312d70 33352d46 543d2d40 52553d31 39303136 3330352d 35366339 2d343337 632d3935 66342d39 33353231 62616432 62653840 533d3333 d1262754 41505344 d428292a 2b2c2d2e 2f5b6170 7362756e 646c6569 6453656e 765f1010 73756273 63726970 74696f6e 2d75726c 5f101072 65667265 73682d69 6e746572 76616c5f 1010636f 6d2e6d65 2e626f6f 6b6d6172 6b735a50 524f4455 4354494f 4e5f1053 68747470 733a2f2f 62616e73 616c766b 73253430 69636c6f 75642e63 6f6d4070 33352d62 6f6f6b6d 61726b73 2e69636c 6f75642e 636f6d2f 38343032 36333033 36382f6d 6d2f7075 73682f72 65676973 74657256 31323030 30301001 5f104d68 74747073 3a2f2f62 616e7361 6c766b73 25343069 636c6f75 642e636f 6d407033 352d626f 6f6b6d61 726b732e 69636c6f 75642e63 6f6d2f38 34303236 33303336 382f7072 696e6369 70616c2f 09090008 0025002a 002f0037 00450053 0062006f 007c0086 009500a3 00b800d1 00e300ff 0133013e 01b30203 02780283 0288028d 0294029d 02a602b4 02bb02c2 02c702c9 02ca02cb 02d202d3 03140317 031c0325 03310335 0348035b 036e0379 03cf03d6 03d80428 04290000 00000000 02010000 00000000 00340000 00000000 00000000 00000000 042a>;
};
Title = "";
WebBookmarkFileVersion = 1;
WebBookmarkType = WebBookmarkTypeList;
WebBookmarkUUID = "FBAA875A-C10A-4744-98BD-DC5EC1D9A009"; }
Before converting any object into json, first check that given object is json convertible or not, you can use following code to check that
if ([NSJSONSerialization isValidJSONObject: plistDict])
{
....
}
Because a JSON Object must be of type NSArray or a NSDictionary while you are passing a NSString.
From the docs :
An object that may be converted to JSON must have the following
properties:
The top level object is an NSArray or NSDictionary.
All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull.
All dictionary keys are instances of NSString.
Numbers are not NaN or infinity.
Your data structure can be successfully read into a NSDictionary instance. But when you serialize it to JSON it fails because it contains parts that cannot be represented as JSON.
My guess is that it's the data at $.Sync.ServerData. This seems to be binary data. JSON doesn't have an data type for binary data.
Remove this element before you serialize it. Or replace it with something else, e.g. a string with a Base-64 representation of the binary data.
The crucial information is
Invalid type in JSON write (__NSCFData)
JSON does not support NSData type (the value of ServerData), you might send the data as string Base64 encoded.
This is the key:
Invalid type in JSON write (__NSCFData)
You cannot serialise NSData to JSON. Try encoding it to string using base-64 (see this answer to do that).
Do this way may be it helps you
{ NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSString *str=[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *dict6 = [self cleanJsonToObject:responseData];
self.handmadeEmbDict = [dict6 objectForKey:#"hemb_list"];
[handmadeEmbTable reloadData];
}
- (id)cleanJsonToObject:(id)data {
NSError* error;
if (data == (id)[NSNull null]){
return [[NSObject alloc] init];
}
id jsonObject;
if ([data isKindOfClass:[NSData class]]){
jsonObject = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
} else {
jsonObject = data;
}
if ([jsonObject isKindOfClass:[NSArray class]]) {
NSMutableArray *array = [jsonObject mutableCopy];
for (int i = (int)array.count-1; i >= 0; i--) {
id a = array[i];
if (a == (id)[NSNull null]){
[array removeObjectAtIndex:i];
} else {
array[i] = [self cleanJsonToObject:a];
}
}
return array;
} else if ([jsonObject isKindOfClass:[NSDictionary class]]) {
NSMutableDictionary *dictionary = [jsonObject mutableCopy];
for(NSString *key in [dictionary allKeys]) {
id d = dictionary[key];
if (d == (id)[NSNull null]){
dictionary[key] = #"";
} else {
dictionary[key] = [self cleanJsonToObject:d];
}
}
return dictionary;
} else {
return jsonObject;
}
}
Swift 2
if let path = NSBundle.mainBundle().pathForResource("try", ofType: "json")
{
do {
let jsonData = try NSData(contentsOfFile:
path, options: NSDataReadingOptions.MappedRead)
let dict = try NSJSONSerialization.JSONObjectWithData(jsonData, options: NSJSONReadingOptions.MutableLeaves)
let rootDict = dict
Print(rootDict)
catch
{
}
}

Getting IPV4 address as a String

Im using Bonjour to browse for available services from specific devices. I can successfully obtain and resolve the services returned from the browse, however I would like to take the service and retrieve it's IPV4 address in String form. To do this I am using the arpa/inet library to translate the NSdata object received by the NSNetService.addresses into a String. The code below works most of the time however occasionally the line below results in the crashing of the app.
NSString *ipString = [NSString stringWithFormat: #"%s",
inet_ntoa(socketAddress->sin_addr)];
The error: EXC_BAD_ACCESS
I am sure it has to do with the way I have declared this code, any ideas?
+ (NSString *)getStringFromAddressData:(NSData *)dataIn {
struct sockaddr_in *socketAddress = nil;
socketAddress = (struct sockaddr_in *)[dataIn bytes];
NSString *ipString = [NSString stringWithFormat: #"%s", inet_ntoa(socketAddress->sin_addr)];
return ipString;
}
Stack trace:
2015-08-13 08:23:45.860 Semiphores[4664:2119558] Stack trace : (
0 Semiphores 0x0000000100001c0b +[BonjourAddressHelper getStringFromAddressData:] + 107
1 Semiphores 0x0000000100007c8a _TFFC10Semiphores17BonjourController15resolveServicesFS0_FPSs9AnyObject_T_U_FT_T_ + 2682
2 Semiphores 0x0000000100007207 _TTRXFo__dT__XFdCb__dT__ + 39
3 libdispatch.dylib 0x00000001006852bb _dispatch_call_block_and_release + 12
4 libdispatch.dylib 0x000000010067fd43 _dispatch_client_callout + 8
5 libdispatch.dylib 0x0000000100683283 _dispatch_root_queue_drain + 1471
6 libdispatch.dylib 0x0000000100694cd0 _dispatch_worker_thread3 + 106
7 libsystem_pthread.dylib 0x00007fff86770637 _pthread_wqthread + 729
8 libsystem_pthread.dylib 0x00007fff8676e40d start_wqthread + 13
)
What would happen if someone passed in nil data?
+ (NSString *)getStringFromAddressData:(NSData *)dataIn {
if (dataIn != nil) {
struct sockaddr_in *socketAddress = nil;
socketAddress = (struct sockaddr_in *)[dataIn bytes];
NSString *ipString = [NSString stringWithFormat: #"%s", inet_ntoa(socketAddress->sin_addr)];
return ipString;
}
return #"";
}

Getting CocoaLibSpotify error in SPPlaylist.m

When I try to build my project i get the following error on line 827
/PATH_TO_PROJECT/Libs/CocoaLibSpotify/Model/SPPlaylist.m:827:25: Implicit conversion of Objective-C pointer type 'AVAssetTrack *' to C pointer type 'sp_track *' (aka 'struct sp_track *') requires a bridged cast
Here is the code where the error occurs:
805 -(void)addItems:(NSArray *)newItems atIndex:(NSUInteger)index callback:(SPErrorableOperationCallback)block {
806
807 SPDispatchAsync(^{
808
809 if (newItems.count == 0) {
810 dispatch_async(dispatch_get_main_queue(), ^{
811 if (block) block([NSError spotifyErrorWithCode:SP_ERROR_INVALID_INDATA]);
812 });
813 return;
814 }
815
816 sp_track **tracks = malloc(sizeof(sp_track *) * newItems.count);
817
818 // libSpotify iterates through the array and inserts each track at the given index,
819 // which ends up reversing the expected order. Defeat this by constructing a backwards
820 // array.
821 for (int currentTrack = (int)newItems.count - 1; currentTrack >= 0; currentTrack--) {
822
823 sp_track *track;
824 id item = [newItems objectAtIndex:currentTrack];
825
826 if ([item isKindOfClass:[SPTrack class]])
827 track = [item track];
828 else
829 track = [(SPTrack *)((SPPlaylistItem *)item).item track];
830
831 tracks[currentTrack] = track;
832 }
833 sp_track *const *trackPointer = tracks;
834
835 if (block)
836 [self.addCallbackStack addObject:block];
837
838 sp_error errorCode = sp_playlist_add_tracks(self.playlist, trackPointer, (int)newItems.count, (int)index, self.session.session);
839 free(tracks);
840 tracks = NULL;
841
842 NSError *error = nil;
843 if (errorCode != SP_ERROR_OK)
844 error = [NSError spotifyErrorWithCode:errorCode];
845
846 if (error && block) {
847 [self.addCallbackStack removeObject:block];
848 dispatch_async(dispatch_get_main_queue(), ^{ block(error); });
849 }
850 });
851 }
Thanks for your help!
The error is pretty self-explanatory - you need to make a bridged cast.
track = (__bridge sp_track *)[item track];
or
track = [(SPPlaylistItem *)item track];

Resources