We have an "iPhone" environment in our Worklight project that we use for our native iOS client development in XCode 5. We are getting an authentication error, despite having App Authentication disabled in the Worklight console.
The steps we're following are:
Call wlConnectWithDelegate: method on WLClient sharedInstance
On success from wlConnectWithDelegate, we invoke our adapter procedure with invokeProcedure:withDelegate:
The code looks like this:
#import <BlocksKit/A2DynamicDelegate.h>
+ (void) connectToWorklightOnSuccess: (SuccessBlock) success onFailure: (FailureBlock) failure {
WLClient *client = [WLClient sharedInstance];
A2DynamicDelegate *dd = [client dynamicDelegateForProtocol: #protocol(WLDelegate) ];
[dd implementMethod: #selector(onSuccess:) withBlock: success];
[dd implementMethod: #selector(onFailure:) withBlock: failure];
[client wlConnectWithDelegate:(id <WLDelegate>)dd];
}
+ (void) invokeProcedure: (WLProcedureInvocationData *) proc onSuccess: (SuccessBlock) success onFailure: (FailureBlock) failure {
[WJServiceGateway connectToWorklightOnSuccess:^(WLResponse *response) {
NSLog(#"WLClient connect succeeded");
WLClient *client = [WLClient sharedInstance];
A2DynamicDelegate *dd = [client dynamicDelegateForProtocol: #protocol(WLDelegate) ];
[dd implementMethod: #selector(onSuccess:) withBlock: success];
[dd implementMethod: #selector(onFailure:) withBlock: failure];
[client invokeProcedure:proc withDelegate:(id<WLDelegate>) dd];
} onFailure:^(WLFailResponse *failResponse) {
NSLog(#"WLClient connect failed: %#", failResponse);
[failure invoke];
}];
}
The first time we our invokeProcedure:onSuccess:onFailure: method, we get an error response:
Status: 403
InvocationResult: (null)
InvocationContext: (null)
Response text: /*-secure-
{"WL-Authentication-Failure":{"wl_antiXSRFRealm":{"reason":"illegal state"}}}*/
Error code: 0
Error message: (null)
Subsequent calls succeed without error until the App is killed and restarted.
This issue may be related to these issues (in fact, this is a problem happening in the same project):
IBM Worklight - How to enable App Authenticity in a native iOS app?
https://stackoverflow.com/questions/18879189/wl-5-0-6-1-js-vs-ios-native-handlechallenge-queued-in-waitlist-and-only-cal
What seems peculiar though, is that we have App Authentication disabled (with the drop-down option in the Worklight console) and are still seeing an authentication error. Is there some other source for this WL-Authentication-Failure/"illegal state" response?
Are we implementing something with our connect and invoke incorrectly here? Is there a solution such that our first adapter invoke after the app starts up doesn't fail?
As mentioned in the comments, this is not related to Application Authenticity Protection.
You need to first invoke a connect to the Worklight Server, and in its success callback to invoke the adapter procedure
You could also only connect to the Worklight Server on application launch, and later on when required to perform the adapter procedure invocation.
For a working example of connect and invoke in a native iOS app, see the following tutorial and sample: https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-6-3/server-side-development/invoking-adapter-procedures-native-ios-applications/
Related
I am trying to post a notification to all registered users with OneSignal.
I have a couple of users registered to test with and have successfully sent a notification form the OneSignal website dashboard.
However, when I try the following code, I get the following errors:
[OneSignal postNotification:#{
#"contents" : #{ #"en" : #"Test Message" },
#"object" : #{ #"en" : #"Test Title" },
#"app_id" : #"MY_SECRET_APP_ID",
}
onSuccess:^(NSDictionary *result) {
}
onFailure:^(NSError *error) {
NSLog(#"%#", error.localizedDescription);
}];
Error:
Create notification failed and The operation couldn’t be completed. (OneSignalError error 400.)
You must use a targeting parameter, only include_player_ids may be used from your app. All other targeting parameters such as tags or segments must be used from your server through the OneSignal create notification REST API POST call. You can get the current OneSignal user / player id by calling IdsAvailable.
To send a notification to all users from your server you will need to add the following to your JSON
"included_segments": ["All"],
Also note, object isn't a valid key so it will be ignored. I believe you are looking for headings based on the value you have.
I am new to liferay. Trying the liferay iOS SDK 7.0.3, I was trying to follow the brief tutorial at https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/invoking-liferay-services-in-your-ios-app
but got stuck early on, with the signInWithSession method.
After establishing a session with [[LRSession alloc] initWithServer: authentication: initWithUserName: password:]
Then I have
[session
onSuccess:^(id result) {
NSLog(#"signIn success");
}
onFailure:^(NSError *e) {
NSLog(#"signIn failure, and error is %#", e);
}
];
[LRSignIn signInWithSession:session callback:session.callback error:&error];
When the username/password combination is wrong, the onFailure gets called, and it prints the error
signIn failure, and error is Error Domain=com.liferay.mobile.sdk Code=2 "java.lang.SecurityException" UserInfo={NSLocalizedDescription=java.lang.SecurityException}
But when a correct username/password combination is used, the onSuccess block does NOT get called. I don't see "signIn success" in the console log.
My imports are
#import "LRBasicAuthentication.h"
#import "LRSession.h"
#import "LRSignIn.h"
Any ideas what may be happening and what I can try?
Gah, it was a bug in the iOS SDK 7.0.3! See https://web.liferay.com/community/forums/-/message_boards/message/71261220 . Apparently, it is fixed in 7.0.4.
At least now I know about the liferay forums ..
Description of error is below:
Error Domain=com.apple.LocalAuthentication Code=-1000 "Pending UI mechanism already set." UserInfo=0x17406b0c0 {NSLocalizedDescription=Pending UI mechanism already set.}
I am also trying Apple's Sample Example app and getting same error. Previously it was working fine, but it has stopped working suddenly ad not working. Please help.
I am using iPhone 6 with iOS 8.1
This code just worked fine for me.
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = #"String explaining why app needs authentication";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
// User authenticated successfully, take appropriate action
NSLog(#"User authenticated successfully, take appropriate action");
} else {
// User did not authenticate successfully, look at error and take appropriate action
NSLog(#"User did not authenticate successfully, look at error and take appropriate action");
}
}];
} else {
// Could not evaluate policy; look at authError and present an appropriate message to user
NSLog(#"Could not evaluate policy: %#",authError);
}
Don't forget to import Local Authentication framework <LocalAuthentication/LAContext.h>. Hope this will solve your issue.
Try rebooting your phone.
I also started getting this error and decided to see if other apps were affected. I have both Dropbox and Mint set up for Touch ID. Sure enough Touch ID wasn't working for them either and they were falling back to passcodes.
I rebooted my phone and it started working again, so it would seem the Touch ID can bug out and stop working. I'm on iOS 8.2 btw.
I guess the proper way to handle this condition is like those apps do and fallback to password / passcode.
I'm using AFNetworking in my app to connect / download data from a web service. This app is deployed via Enterprise deployment to users at various locations. At one of the locations where people use our app, the wifi network seems to randomly go down / come back up in a few seconds. In these cases, the requirement was to retry a request thrice before giving up and failing. I've got the retry part of it working fine, but have some problems detecting a network failure. Some code:
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:
^(AFHTTPRequestOperation *operation, id responseObject) {
[self parseResponse:operation.responseString];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self messageFailureWithCode:error.code
reason:[NSString stringWithFormat:#"%#", error]];
}
];
The error code I'm retrying on is NSURLErrorTimedOut. But I just got another log file which indicated a failure with the following error: -1003 "A server with the specified hostname could not be found."
I could add this code to my list too, but I wanted to be sure that I'm capturing all the errors and not just handling them as they appear. I was looking through the NSURLError.h file and found the following error codes that vaguely look like they could be caused by a network failure.
Can someone help me figuring out under what conditions each error is triggered and if I'm missing any error codes? The list is below:
NSURLErrorCannotFindHost
NSURLErrorTimedOut
NSURLErrorCannotConnectToHost
NSURLErrorNetworkConnectionLost
NSURLErrorDNSLookupFailed
NSURLErrorResourceUnavailable
NSURLErrorNotConnectedToInternet
Thanks,
Teja.
It sounds like you could safely just retry every failure with an error domain of NSURLErrorDomain (exempting the case where an operation was cancelled). That should cover all of those cases.
I am trying out adding facebook integration in an app using the new (beta) facebook ios sdk 3.0. All I would like to is post a status update to facebook. I used a FBLoginView to login to facebook. I put my app id in the plist as instructed on facebook. I put in some code to post to facebook.
(void)viewDidLoad
{
[super viewDidLoad];
NSArray *perms;
perms = [NSArray arrayWithObjects:#"status_update", nil];
FBLoginView *loginview =
[[FBLoginView alloc] initWithPermissions:perms];
loginview.frame = CGRectOffset(loginview.frame, 5, 5);
loginview.delegate = self;
[self.view addSubview:loginview];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)poststatus:(UIButton *)sender {
NSString *message = [NSString stringWithFormat:#"Test staus update"];
[FBRequestConnection startForPostStatusUpdate:message
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[self showAlert:message result:result error:error];
}];
}
- (void)showAlert:(NSString *)message
result:(id)result
error:(NSError *)error {
NSString *alertMsg;
NSString *alertTitle;
if (error) {
alertMsg = error.localizedDescription;
alertTitle = #"Error";
} else {
NSDictionary *resultDict = (NSDictionary *)result;
alertMsg = [NSString stringWithFormat:#"Successfully posted '%#'.\nPost ID: %#",
message, [resultDict valueForKey:#"id"]];
alertTitle = #"Success";
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:alertTitle
message:alertMsg
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
The odd thing is, this code works ONCE. After authenticating the user for the first time, I can post ONE status update successfully. After that, all subsequent attempts will fail with a FBiOSSDK error 5 (in the console, Error: HTTP status code:400). The only way to fix this is to remove the app from the facebook account and re-authenticate. I'm not sure what the problem is. I looked online for solutions but couldn't find anything. If anyone knows how to fix this, please let me know. Thanks
com.facebook.sdk error 5 is always irritating while working with Facebook iOS sdk. Most of the times it comes with addional in console Error: HTTP status code:400. Its a perception that there is a bug in Facebook iOS sdk that produces this error randomly. I think this error occurs for some certain reasons and sdk do not provide actual reason of error when it occurs.
Several Possible Reasons
Every request in sdk is accomplished with completion blocks that we actually pass as argument in completionHandler. This error occurs when a block is in progress and made another request. A simple example might be If you have written request to post on Facebook (startForPostStatusUpdate::) on some button action. On single button tap it would work fine but if you double tap on button it will throw this error com.facebook.sdk error 5
If you are trying to post when your current session is not opened. e.g. Once sign in with Facebook then kill the app then reopen and then try to share on Facebook, Result -> com.facebook.sdk error 5. In this case try to reopen session using
Facebook do not allow same status to be posted repeatedly, they think it might be some kind of spam e.g. If you are trying to update status and you have hard coded a string lets say #”This is a test status update” you are posing again and again. After 5 to 10 attempts they wont allow you to do anymore. Resulting com.facebook.sdk error 5. If this is the scenario you should change your status string and try updating.
Facebook has defined a limit for a particular user to post status using sdk. e.g If you are trying to update status and you have done lets say 15 to 20 status updates. They wont let you do more Resulting -> com.facebook.sdk error 5. In this scenario try to unauthorize the app from your Facebook account and reauthorize it OR try using other Facebook account
It seems there might be no answer to the issue. I have checked FB samples coming with SDK, in these examples also the same error happens. So it means after few status updates (15-20) Facebook reaches limits for that particular user. If you log-out for that user and log-in as another user, you can successfully post.
If I will find any extension to limit settings I will reply.
Also Facebook doesn't allow for the same Post.
Use a proxy !
FB ios SDK is just a wrap to an HTTP request to graph.facebook.com/....?access_token=.....
So you can easily replicate the request or use an HTTP proxy to see the real server answer (which is not error 5 !).