php mysql = NSString

Discussion in 'iOS Programming' started by IDMah, Dec 8, 2013.

  1. IDMah macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #1
    Is there any chance that php/mysql/Json is messing up my string compare.

    Using this:

    Code:
     if ([iuuDee isEqualToString:myShareSingHS.uuidStringThing]) {
                       NSLog(@"Dude you have been BANNED");
                       // flag a message to be show //
                       // also add an option to do not display again flag // 
                       // remind me later // 
                   }
    
    
    when I print it they look the same..
    Any ideas.

    thanks
    Ian
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    General development principle: Break It Down.

    General debugging principle: Inspect the Details.


    What is the length of each string?

    What are the hex values of the characters (unichar) that make up each string? (Use the method characterAtIndex:)

    Write test code that displays data that answers the above questions.
    Then post the code, and the data it outputs.
     
  3. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #3
    talking to myself to help others..

    Your Error was in the code before where you test for a null string.
    so nothing got triggered. as a *Note nil and Null are not the same thing.

    You need to test for the <NULL> first.

    Code:
     // was if (!uuDee) which basically a stupid mistake and if (uuDee) crashed 
     //  because you can't compare a NULL string to a string 
     //  so ... do this // 
     if ( ![iuuDee  isKindOfClass:[NSNull class]]){
                   if ([iuuDee isEqualToString:myShareSingHS.uuidStringThing]) {
                       NSLog(@"Dude you have been BANNED");
                       // flag a message to be show //
                       // also add an option to do not display again flag // 
                       // remind me later // 
                   }
               }
    
    Now everything works fine.. also changed the MySQL type to BLOB.

    Hope this helps.
     
  4. Sonnestah macrumors regular

    Joined:
    Mar 2, 2013
    #4
    blob for an uuid string?!
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    How are you getting UUID? Be aware that UIDevice's uniqueIdentifier property is now deprecated and only available for devices running iOS 2.0 through iOS 6.1.
     
  6. MattInOz macrumors 68030

    MattInOz

    Joined:
    Jan 19, 2006
    Location:
    Sydney
    #6
    If your getting a NULL then that suggest to me your being returned a CFString not a NSString from the function feeding uuiDee.
     
  7. IDMah, Dec 12, 2013
    Last edited: Dec 12, 2013

    IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #7
    Hi Dejo..

    I found a uuid replacement -- somewhere on StackOverflow.

    Code:
    - (NSString *)uuidString {
        // Returns a UUID
        
        CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
        NSString *uuidStr = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
        CFRelease(uuid);
        NSLog(@"Generated uuid: %@",uuidStr);
        return uuidStr;
    }
    
    
    This should be ok with apple right? and I don't really care if it dies if the user deletes the app, because they deleted my app !!! Hahah!! but seriously it's just helps me keep track of players if I have to ban them..

    In terms of the NULL I'm getting it from the mySQL, PHP. basically I want to keep it from crashing. I have tried various mySQL options and it's better I think to just check it in Xcode. I did set it to a NSString unless the JSON is returning the CFString..

    i use this:
    Code:
     NSURLRequest *request = [NSURLRequest requestWithURL:theLatestHighScoreURL];
        [NSURLConnection sendAsynchronousRequest:request
                                           queue:[NSOperationQueue mainQueue] 
                               completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                                   // You have it.
                                   NSLog(@"got data");
                                   if (error) {
                                       NSLog(@"Something happended");
                                   }else{
                                   [self fetchedData:data];
                                   }
                               }];
      }
    
    and then "parse" the dictionary. is Parse the right term?
    But basically the previous code works..

    thanks
    Ian
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    You sure that CFUUID is available for iOS and not just OS X?
     
  9. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #9
    See the Apple-recommended replacement for UDIDs on iOS here:
    https://developer.apple.com/library...erence/UIDevice_Class/Reference/UIDevice.html

    uniqueIdentifier
    An alphanumeric string unique to each device based on various hardware details. (read-only) (Available in iOS 2.0 through iOS 6.1. Use the identifierForVendor property of this class or the advertisingIdentifier property of the ASIdentifierManager class instead, as appropriate, or use the UUID method of the NSUUID class to create a UUID and write it to the user defaults database.)
    That extract is the discussion under the deprecated uniqueIdentifier property.

    Also, the device's UDID (which is deprecated) is not the same as a UUID.

    Since iOS has an NSUUID class, and that class has a method that returns an NSString, I don't see any point in writing code to make one from CFUUIDRef.
    https://developer.apple.com/library...ence/Reference.html#//apple_ref/occ/cl/NSUUID
     
  10. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #10
    the "sales person" ;) the poster said it work for ios 7.
    and so far it's worked on everything I've tried..

    but will look at: UIDevice Class Reference

    Like I said. I could have just as easily just created a unique random number generator,
    just something to unique.

    thanks.
     

Share This Page