Advertisement
Guest User

Untitled

a guest
Dec 16th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include "KochavaUnitySupport.h"
  2.  
  3. char* AutonomousStringCopy (const char* string)
  4. {
  5.     if (string == NULL)
  6.         return NULL;
  7.    
  8.     char* res = (char*)malloc(strlen(string) + 1);
  9.     strcpy(res, string);
  10.     return res;
  11. }
  12.  
  13. extern "C" {
  14.     char* GetExternalKochavaInfo()
  15.     {
  16.        
  17.        
  18.         NSDictionary *kochavaInfo = [[KochavaUnitySupport sharedManager] returnKochavaInfo];
  19.        
  20.        
  21.         //Works great for iOS 5
  22.         NSError *error;
  23.         NSData *jsonData = [NSJSONSerialization dataWithJSONObject:kochavaInfo options:0 error:&error];
  24.         if (! jsonData) {
  25.             NSLog(@"Got an error: %@", error);
  26.             return AutonomousStringCopy("");
  27.         }
  28.        
  29.         NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  30.         NSLog (@"%@", jsonString);
  31.  
  32.         const char* jsonChar = AutonomousStringCopy([jsonString UTF8String]);
  33.         return AutonomousStringCopy(jsonChar);
  34.        
  35.         //Need to loop through the NSDictionary manually and create the JSON object with a string builder
  36.        
  37.         /*
  38.         for(NSString* key in kochavaInfo)
  39.         {
  40.             NSObject* val = [kochavaInfo objectForKey:key];
  41.            
  42.             NSLog (@"%@", [key UTF8String]);
  43.             //NSLog (@"%@", [val UTF8String]);
  44.             NSLog (@"-----@");
  45.          
  46.         }
  47.         */
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement