How to have multiple subclasses of MKNetworkKit? - objective-c

I am currently using MKNetworkKit to cache the download of several images from a restful server. I have another restful service I ping to get supplemental information about the images. Whichever server I ping first works, but when pinging the second server I get the following error:
[The operation couldn’t be completed. (NSURLErrorDomain error 404.)]
2012-08-12 19:51:12.340 [51853:11603]
Error: Error Domain=NSURLErrorDomain Code=404 "The operation couldn’t be completed. (NSURLErrorDomain error 404.)" UserInfo=0x73c5490 {Server=Apache-Coyote/1.1, Content-Length=47, Content-Type=text/html;charset=ISO-8859-1, Connection=keep-alive, Date=Sun, 12 Aug 2012 23:51:11 GMT}
2012-08-12 19:51:12.341 [MKNetworkOperation operationFailedWithError:] [Line 1280] State: 0
MKNetworkKit is pinging the first server in attempt to get data from the second server's URL. I think I may need to create another reachability object? Any idea what I'm doing wrong? Or where I can find some example implementation of one project with multiple subclasses?
Edit
I implement both engines the following way:
#implementation FirstEngine
FirstEngine* _sharedEngine;
+(FirstEngine*)sharedEngine
{
if(_sharedEngine==nil)
{
_sharedEngine = [[FirstEngine alloc] initWithHostName:#"***.**.**.**" customHeaderFields:nil];
}
return _sharedEngine;
}
and invoke them this way:
$[[FirstEngine sharedEngine] bodyForPath:url verb:verb body:params onCompletion:^(NSDictionary* body)
{}....
or
$[[SecondEngine sharedEngine] bodyForPath:url verb:verb body:params onCompletion:^(NSDictionary* body)
{}....

You should create a MKNetworkEngine object in your AppDelegate for "every" server you talk to.
self.imageCacheEngine = [[MKNetworkEngine alloc] initWithHostName:#"images.myserver.com"];
and
self.apiEngine = [[MKNetworkEngine alloc] initWithHostName:#"api.myserver.com"];
Enqueue image requests to the imageCacheEngine and api requests to your apiEngine.

Related

WSO2 API Manager returning RunTime Error

I have an API in WSO2. When I try to test it in the store with valid parameters via GET, it returns the following error message:
<am:fault xmlns:am="http://wso2.org/apimanager">
<am:code>101504</am:code>
<am:type>Status report</am:type>
<am:message>Runtime Error</am:message>
<am:description>Send timeout</am:description>
</am:fault>
I have already searched and tried a lot, but with no success, always returning the same error. Don't know if helps, but the api that I try to access is a PHP file.
Any ideas?
EDIT:
I have identical apis to this one, changing only the response, that are working properly. Even if I erase the php file that the API is pointing, the error keep coming.
EDIT:
I changed the code in Management Console, in Metadata>List>APIs:
{"production_endpoints":
{"url":"http://site/myapi.php","config":
{"format":"leave-as-is","optimize":"leave-as-
is","actionSelect":"fault","actionDuration":30000}},
"sandbox_endpoints":
{"url":"http://site/myapi.php","config":
{"format":"leave-as-is","optimize":"leave-as-
is","actionSelect":"fault","actionDuration":30000}},
"implementation_status":"managed","endpoint_type":"http"}
to this:
{"production_endpoints":
{"url":"http://10.20.40.189/ConsultaAutorizacaoCadPos.php","config":null},
"sandbox_endpoints":{"url":"http://10.20.40.189/ConsultaAutorizacaoCadPos.php","config":null},
"implementation_status":"managed","endpoint_type":"http"}
And this error message vanishes. But this new one appears:
<am:fault xmlns:am="http://wso2.org/apimanager">
<am:code>303001</am:code>
<am:type>Status report</am:type>
<am:message>Runtime Error</am:message>
<am:description>Currently , Address endpoint : [ Name : admin--myapi_APIproductionEndpoint_0 ] [ State : SUSPENDED ]</am:description>
EDIT: this error message is appearing just sometimes. Most of the time the request takes long time to run and then returns nothing( no content )
Any ideas how to solve it?

__tcp_connection_write_eof_block_invoke Write close callback received error: [89] Operation canceled

I am getting this when uploading to server in this API I am uploading audio file and text data and if I remove audio it is working fine and I am getting this error in iOS 10. In iOS below 10 it's working fine all data is getting uploaded.
Error: The request timed out. 2016-11-11 10:17:26.263019 Smart Child Info[1407:423623] [] __tcp_connection_write_eof_block_invoke Write close callback received error: [89] Operation canceled
Seems that your request timed out, try (assuming you are using NSMutableURLRequest and you want a timeout of 120 seconds):
request.timeoutInterval = 120;

CNContactStore enumerateContactsWithFetchRequest 'Failed to update account' error

I'm trying to fetch all contacts from El Capitan, and I'm using the Contacts API to do so. Here is the method where I fetch the contacts:
-(void)getAllContacts{
NSError* contactError;
//initialize the contact store
CNContactStore* addressBook = [[CNContactStore alloc]init];
//specify the fields I need
NSArray * keysToFetch =#[CNContactEmailAddressesKey, CNContactPhoneNumbersKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName]];
//establish the request with the above keys
CNContactFetchRequest * request = [[CNContactFetchRequest alloc]initWithKeysToFetch:keysToFetch];
//fetch all the contacts
BOOL success = [addressBook enumerateContactsWithFetchRequest:request error:&contactError usingBlock:^(CNContact * __nonnull contact, BOOL * __nonnull stop){
//I'm doing nothing here to try to isolate the problem, but even if I do something here, the problem remains
}];
//success is always true
//contactError is always nil
//5 or so seconds later, I see the error output to the console
}
Nothing fancy going on, but I everytime after this method executes, 5-10 seconds later the following error is output to the console:
[Accounts] Failed to update account with identifier 72360D58-3D7H-49FC-1086-QRCIEQ8A991A0, error: Error Domain=ABAddressBookErrorDomain Code=1002 "(null)"
I'm not explicitly trying to update any accounts. If I don't include the enumerateContactsWithFetchRequest call, then no error is output. I've tried this on multiple different Macs with different contact lists, and I get this same error. I am also checking that the CNContactStore authorization status is CNAuthorizationStatusAuthorized before I invoke getAllContacts.
This is really frustrating, I'm starting to suspect this might be a bug in the Contacts API? Has anyone else seen this issue, or have any idea what might be causing it? Thanks for the help!
PS. I changed the ID of the account in the error statement in case that is a security concern :)

mod_perl error returning 202 Apache2::Const::HTTP_ACCEPTED

I am trying to build a simple asynchronous web service with Apache and mod_perl. But every time I try to return HTTP status 202 (Accepted), I get an error.
Below a very simple example (non-asynchronous):
package MyHandler;
use Apache2::Const '-compile' => qw 'OK HTTP_ACCEPTED HTTP_OK';
use Apache2::RequestRec;
use CGI;
sub handler {
my $r = shift;
print "Hallo";
$r->content_type('text/plain');
$r->status(Apache2::Const::HTTP_ACCEPTED);
return Apache2::Const::HTTP_ACCEPTED;
}
1;
I get the error
calling the handler in my browser on localhost, I get the output but also an error:
Hallo
Accepted
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
I also get an error with Apache2::Const::HTTP_OK, the only one that works without error is Apache2::Const::OK.
My apache error log makes no mention of this error.
With mod_perl2 you do not return HTTP status codes (this is why it is necessary to use $r->status() so set the HTTP status code.
Instead, you return a value depending on what you want the server to do. The most common would be Apache2::Const::OK. This tells the server your handler has finished successfully. This constant, if I recall correctly, has an integer value of 0, not 200.
Returning an HTTP status code from a mod_perl handler will be interpreted as an error.
https://perl.apache.org/docs/2.0/user/handlers/intro.html#Handler_Return_Values
Different handler groups are supposed to return different values.
Make sure that you always explicitly return a wanted value and don't rely on the result of last expression to be used as the return value -- things will change in the future and you won't know why things aren't working anymore.
The only value that can be returned by all handlers is Apache2::Const::OK, which tells Apache that the handler has successfully finished its execution.
Apache2::Const::DECLINED is another return value that indicates success, but it's only relevant for phases of type RUN_FIRST.
HTTP handlers may also return Apache2::Const::DONE which tells Apache to stop the normal HTTP request cycle and fast forward to the PerlLogHandler, followed by PerlCleanupHandler. HTTP handlers may return any HTTP status, which similarly to Apache2::Const::DONE will cause an abort of the request cycle, by also will be interpreted as an error. Therefore you don't want to return Apache2::Const::HTTP_OK from your HTTP response handler, but Apache2::Const::OK and Apache will send the 200 OK status by itself.
Try NOT printing anything BEFORE you set your content-type header.

Error messages in iOS CoreData + iCloud after deleting and redeploying app

The application has been put in iCloud since the beginning, so I have the opportunities to fill it with data, and see synchronization happening on other devices.
However I am starting to have problems after deleting and redeploying the application on one device only.
In particular, at startup, it's taking a lot at this point:
NSLog(#"add coordinator");
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
NSLog(#"finish");
I can see "add coordinator" in console, then it seems to be in pause forever. Instead by activating core data logging, I can see that is doing a lot of select and update.
Then an infinite list of log error messages for each transactionNumber is shown:
CoreData: Ubiquity: Error importing transaction log: <PFUbiquityTransactionLog: 0x1929e350>
transactionLogLocation: <PFUbiquityLocation: 0x17bf1c40>: /private/var/mobile/Library/Mobile Documents/6G8M57K6MU~myapp/mobile.63606F7B-D6A9-5937-9160-126AC1315EBF/myAppCloud/3IEWV8FXM6GJ58H5PkyqFsyuoUZ2qIOuJOfon1QIYC4=/035A5A1C-F893-4B67-A784-866A4DE1B3F1.1.cdt
transactionNumber: 1
, exception: -[__NSCFDictionary setObject:forKey:]: attempt to insert nil key
-[_PFUbiquityRecordsImporter operation:failedWithError:](839): CoreData: Ubiquity: Import operation encountered an error: Error Domain=NSCocoaErrorDomain Code=134060 "The operation couldn’t be completed. (Cocoa error 134060.)" UserInfo=0x194c9f40 {exception=-[__NSCFDictionary setObject:forKey:]: attempt to insert nil key} while trying to import the log file at the URL: <PFUbiquityTransactionLog: 0x1929e350>
transactionLogLocation: <PFUbiquityLocation: 0x17bf1c40>: /private/var/mobile/Library/Mobile Documents/6G8M57K6MU~myapp/mobile.63606F7B-D6A9-5937-9160-126AC1315EBF/myAppCloud/3IEWV8FXM6GJ58H5PkyqFsyuoUZ2qIOuJOfon1QIYC4=/035A5A1C-F893-4B67-A784-866A4DE1B3F1.1.cdt
transactionNumber: 1
Then as I said, the "finish" is printed, and the app doesn't to have any data at all.
An Apple engineer replied me to a post I did on Apple Dev forum, stating that this is a known bug that has been fixed on forthcoming iOS 6.
So, there's no solution than scratching all data on devices and start again.
At this point, I suppose I will ship with CoreData without iCloud.