dimanche 30 novembre 2014

My JSONObjectWithData is null

I have a problem with my JSON who send me a null value.


I think it's not a problem with my webservice in PhP because my colleague who is a expert in PhP doesn't see any error


Just below my Obj-C code



dispatch_queue_t downloadQueue = dispatch_queue_create("downloader", NULL);

dispatch_async(downloadQueue, ^{
NSData *result = self.envoyerLaDemande;
dispatch_async(dispatch_get_main_queue(), ^{

id strResult=nil;

strResult = [NSJSONSerialization JSONObjectWithData:result options:0 error:nil];

NSLog(@"strResult: %@", strResult);

NSString* boolOk=[strResult objectForKey:@"result"];
NSLog(@"BoolOk: %@", boolOk);


And there is the PHP script



$data = array();

if(condition == 1)
{
$data["result"] = "ok";
}
else
{
$data["result"] = "error";
}
$data["result"] = "coucou";
}
echo json_encode($data);


And the methode envoyerLaDemande



-(NSData*)envoyerLaDemande{


NSURL *url = [NSURL URLWithString:@"http://mywebsite.com.com/App/V2/mailTo.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

NSString* requestFields;


requestFields = [NSString stringWithFormat:@"agence=%@&", nomAgence];

request.HTTPBody = requestData;
request.HTTPMethod = @"POST";

NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (error == nil && response.statusCode == 200) {
} else {
}
return responseData;

}



How to implement Pocket-like screen orientation lock?

Is there a way to lock the iPhone's screen orientation programmatically? Just like the Pocket app provides a lock button every time when the screen orientation changes, and the user can click the lock button to lock the screen orientation. I wonder how to implement a feature like this.


I searched the web and found these 2 related posts, but still can't find the solution.


http://forums.macrumors.com/showthread.php?t=1579703


http://www.quora.com/Is-Pockets-screen-orientation-lock-patented-Why-dont-other-apps-OSes-have-it


Thanks in advance.




Check whether a token is belong to `iPhone` or `Android`

I'm looking a way to check whether a token I get is belong to iPhone or Android in C#?


I found an information about that : difference between iOS, Android token


From my test that I did my Android token is 183 digits and iPhone is 64 digits, while the Android token start with the digits : 'APA..........."


Any ideas how to check it for 100% ?




instantiateViewControllerWithIdentifier not calling ViewDidLoad

I'm using instantiateViewControllerWithIdentifier to get a viewController from Storyboard in order to assign it as a root viewController for a navigationController, so i do that:



self.welcomeView=(WelcomeView*)[self.storyboard instantiateViewControllerWithIdentifier:@"WelcomeView"];


and in order to set self.welcomeView as a root view controller for the navigation controller i do that:



[self.navigationController setViewControllers:@[self.welcomeView] animated:NO];


the problem is that ViewDidLoad of WelcomeView didn't called and as a result the rootViewController of the navigation controller appears blank, i don't know why this happens!




iOS GCD: DISPATCH_QUEUE_PRIORITY_BACKGROUND, what does "disk I/O is throttled" mean in document?

As the document says:



DISPATCH_QUEUE_PRIORITY_BACKGROUND Items dispatched to the queue will run at background priority, i.e. the queue will be scheduled for execution after all higher priority queues have been scheduled and the system will run items on this queue on a thread with background status as per setpriority(2) (i.e. disk I/O is throttled and the thread’s scheduling priority is set to lowest value).



The last part of the document, what does "disk I/O is throttled" mean here?


Does it mean that tasks running at DISPATCH_QUEUE_PRIORITY_BACKGROUND level can't access disk?




get birthday days from ios calendars on user's iPhone

I want to access user's calender and get only birthdays from ios calanders to myapp on user's iPhone. it's possible or not ?


enter image description here




How to completely remove app from iOS?

There is an app called X in my iPhone which can tell you whether or not you have installed other apps before in this iPhone.


Then I installed an app A into my iPhone, and app X tells me A has not been installed before.


Then I uninstalled app A and then reinstalled it, and app X tells me A has been installed before.


How does X know that A has been installed or not?


And how can I completely remove app A and let app X tells me A has not been installed?


I have jailbreaked my iPhone, is there any app can do that?