`PFFile getDataInBackgroundWithBlock` block not getting called Obj-C - parse-platform

I have the following code, to retrieve an image from Parse. This code block is in a recursive loop that gets called for a list of images in an array.
PFFile *remoteImageFile = object[#"Image"]
[remoteImageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
DDLogInfo(#"%s:%d %#", __PRETTY_FUNCTION__, __LINE__, [error debugDescription]);
// other logics
}];
The code fetches most of the images successfully, the sizes of the images being 2MB to 3MB. But randomly it fails for certain files and the block is not getting fired and my whole fetching operation freezes. Couldn't find the reason.
Any help please

I doubt that there is a bug in the Parse framework here. The most probable cause is that your remoteImageFile is nil which means that getDataInBackgroundWithBlock: is not even called.
Can you check by using the following code :
PFFile *remoteImageFile = object[#"Image"];
if (remoteImageFile == nil || ![remoteImageFile isKindOfClass:[PFFile class]]) {
NSLog(#"Error : remoteImageFile = %#", remoteImageFile);
} else {
[remoteImageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
DDLogInfo(#"%s:%d %#", __PRETTY_FUNCTION__, __LINE__, [error debugDescription]);
// other logics
}];
}

Related

OSX CryptoTokenKit SmartCard returned error 6d00

I'm trying to read the master file of a smartcard on OSX using CryptoTokenKit but I always get statusword 6d00 as response. I also tried to run the trivial example with some modifications but get the same error. My reader is Gemalto PC Twin Reader.
Please let me know if you have any suggestion to fix it.
I'm using the following code:
TKSmartCardSlot *slot = [self.smartCardManager slotWithName:slotName];
TKSmartCard *card = [slot makeSmartCard];
card.sensitive = YES;
[card beginSessionWithReply:^(BOOL success, NSError *error) {
NSLog(#"%#", error);
NSLog(#"Proto: %ld", card.currentProtocol);
NSData *data = [CommonUtil dataFromHexString:#"3F00"]; //<3f00>
NSLog(#"%#", data);
[card sendIns:0xA4 p1:0x00 p2:0x00 data:data le:#0
reply:^(NSData *replyData, UInt16 sw, NSError *error)
{
NSLog(#"Response: %#", replyData);
if (error) {
if (error.code == TKErrorCodeCommunicationError) {
// set response error code.
}
NSLog(#"%#", error);
}
}];
}];
It is silly, but in the apdu where no response data is expected without the success code 90 00, le should be nil.
[card sendIns:0xA4 p1:0x00 p2:0x00 data:nil le:nil
reply:^(NSData *replyData, UInt16 sw, NSError *error)
{
}
Status Word 6D00 is " Instruction code not supported or invalid "
http://www.cardwerk.com/smartcards/smartcard_standard_ISO7816-4_5_basic_organizations.aspx
Not all the cards allow to select the Master File (0x3F00).

How to get all name of RecordType in a private Database CloudKit

I would like to know how I can get an array with all the name of record type in my private database in Cloud Kit for read all my data ?
I save my data :
CKRecord* fav1 = [[CKRecord alloc] initWithRecordType:#"Favoris1"];
[fav1 setObject:#"Favoris 1 name"forKey:#"name"];
[fav1 setObject:#"2003 year"forKey:#"year"];
[self.privateDatabase saveRecord:fav1
completionHandler:^(CKRecord *savedState, NSError *error) {
if (error) {
NSLog(#"ERROR SAVING: %#", error);
}
else{
NSLog(#"SAVE OK");
}
}];
I read my data :
CKQuery *query = [[CKQuery alloc] initWithRecordType:#"Favoris1" predicate:[NSPredicate predicateWithFormat:#"TRUEPREDICATE"]];
[self.privateDatabase performQuery:query
inZoneWithID:nil
completionHandler:^(NSArray *results, NSError *error)
{
if (!error)
{
NSLog(#"results query %#", results);
NSLog(#"--> %#",[[results objectAtIndex:0] objectForKey:#"name"]);
NSLog(#"--> %#",[[results objectAtIndex:0] objectForKey:#"year"]);
}
else
{
NSLog(#"FETCH ERROR: %#", error);
}
}];
I would like to save an other record with another properties like :
CKRecord* fav2 = [[CKRecord alloc] initWithRecordType:#"Favoris2"];
[fav2 setObject:#"Favoris 2 name"forKey:#"name"];
[fav2 setObject:#"2005 year"forKey:#"year"];
How can I have an array with Favoris1 and Favoris2 for read all my record after I have saved ?
in CloudKit there is no function that will return all the available recordType's from a database. You can also not query multiple recordTypes at the same time. You have to perform 2 queries. What you could do is join the resulting arrays together if you need something like that.
Since the objects are the same, it would be better if you just used 1 recordType and add an extra field that would specify your custom type (Favoris1 or Favoris2) Then you could query just the recordType and see in the returned field what custom type it is.

Twilio iOS unrecognized selector sent to Class

I'm new to using Twilio and I'm hoping someone can help me debug my app.
I am making a call to get a capability token and it is returned just fine. I print it in the console to check then it appears when I make the call to initWithCapabilityToken that's where something is breaking and I cant figure it out.
Here is my code...
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:
^(NSURLResponse *response, NSData *data, NSError *error){
// Log Any Reply
if ([data length] >0 && error == nil) {
NSData *jsonData = data;
// Deserialize JSON into Dictionary
error = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingAllowFragments
error:&error ];
if (jsonObject != nil && error == nil) {
NSLog(#"Successfully deserialized JSON response...");
if ([jsonObject isKindOfClass:[NSDictionary class]]) {
NSDictionary *deserializedDictionary = (NSDictionary *)jsonObject;
NSLog(#"Deserialized JSON Dictionary = %#", deserializedDictionary);
NSString *token = [deserializedDictionary objectForKey:#"token"];
if (token == nil) {
NSLog(#"Error retrieving token");
} else {
NSLog(#"Token: %#", token);
// Setup TCDevice
_phone = [[TCDevice alloc] initWithCapabilityToken:token delegate:self];
}
}
} else if (error != nil){
NSLog(#"An error happened while de-serializing the JSON data.");
}
}else if ([data length] == 0 && error == nil){
NSLog(#"Nothing was downloaded.");
}else if (error != nil){
NSLog(#"Error happened = %#", error);
}
}];
Here is what I get right after my token is logged...
2015-01-29 16:32:14.637 AppName[4649:701822] +[NSString stringWithPJStr:]: unrecognized selector sent to class 0x3377da98
2015-01-29 16:32:14.639 AppName[4649:701822] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSString stringWithPJStr:]: unrecognized selector sent to class 0x3377da98'
*** First throw call stack:
(0x254da49f 0x32c90c8b 0x254df7d5 0x254dd7d7 0x2540f058 0x10ee7d 0x10e32b 0x10e2b7 0x105959 0x10568d 0x7b3ab 0x24fa228d 0x261d52b1 0x2614034d 0x26132b07 0x261d7c1b 0x487e29 0x4822c9 0x489567 0x48a891 0x33351e31 0x33351b84)
libc++abi.dylib: terminating with uncaught exception of type NSException
Thanks
After reading all of Twilios documentation I discovered I was missing one thing. I had to add -ObjC to Other Linker Flags and that solved my problem.
add this lines to the other linker flags:
-ObjC
-lTwilioClient
-lcrypto
-lssl
it worked for me only with a upper C add the end (-ObjC)
Somewhere you are calling a stringWithPJStr function(selector) that doesn't exist.

What could cause NSMigrationManager to return a nil error?

I have this code:
NSError *error; // NSMigrationManager hates it if you don't provide an error pointer
BOOL result = [manager migrateStoreFromURL:sStoreURL
type:NSSQLiteStoreType
options:nil
withMappingModel:mappingModel
toDestinationURL:dStoreURL
destinationType:NSBinaryStoreType
destinationOptions:nil
error:&error];
To my surprise, it's sometimes returning NO and leaving/setting the error pointer to nil. What can cause this?
This is caused if you have a custom migration policy that returns NO without setting the error pointer. e.g.
- (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sInstance entityMapping:(NSEntityMapping *)mapping manager:(SVMigrationManager *)manager error:(NSError **)error;
{
return NO;
}
Check the code carefully to find any situations where this could occur.

Clang Error on "Potential null dereference."

I keep getting Clang errors on the following type of code and I can't figure out why they're erroneous or how to resolve them to Clang's satisfaction:
+ (NSString *)checkForLength: (NSString *)theString error: (NSError **)error {
BOOL hasLength = ([theString length] > 0);
if (hasLength) return theString;
else {
*error = [NSError errorWithDomain:#"ErrorDomain" code:hasLength userInfo:nil];
return nil;
}
}
Leaving aside the utterly-contrived nature of the example (which Clang did object to so it's illustrative enough), Clang balks at the error assignment line with the following objection:
Potential null dereference. According to coding standards in 'Creating and Returning NSError Objects' the parameter 'error' may be null.
I like having a pristine Clang report. I've read the cited document and I can't see a way to do what's expected; I checked some open-source Cocoa libraries and this seems to be a common idiom. Any ideas?
The way to do what's expected is shown in listing 3-5 in that document. With your example code:
+ (NSString *)checkForLength: (NSString *)theString error: (NSError **)error {
BOOL hasLength = ([theString length] > 0);
if (hasLength) return theString;
else {
if (error != NULL) *error = [NSError errorWithDomain:#"ErrorDomain" code:hasLength userInfo:nil];
return nil;
}
}
The Cocoa convention is that the return value should indicate success or failure (in this case, you return nil for failure) and the error is filled in with additional information, but only when the caller requests it.
In other words
NSError *error = nil;
NSString *result = [self checkForLength: aString error: &error];
and
NSString *result = [self checkForLength: aString error: NULL];
are both valid ways to invoke the method. So the method body should always check for a NULL error param:
if (error != NULL)
*error = ...;

Resources