I want to send a resource with Multipeer Connectivity framework, see below. But the strange thing is that the log says:
[self.mySession connectedPeers]: (
"<MCPeerID: 0x10fc9d60 DisplayName = iPad>"
)
Error: Peer not connected
So peer is connected, and in the next line says it is not connected. How, why? All the delegate methods are implemented well on client side.
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"[self.mySession connectedPeers]: %#", [self.mySession connectedPeers]);
[self.mySession sendResourceAtURL:u withName:#"apple" toPeer:[self.mySession connectedPeers] withCompletionHandler:^(NSError *error) {
if (error) {
NSLog(#"Error: %#", [error localizedDescription]);
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"MCDemo"
message:#"File was successfully sent."
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"Great!", nil];
[alert performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:NO];
}
}];
});
Related
I need to implement touch ID and have to show alert to user for authentication attempts left. Below code Im using.
reply block not getting called after one wrong authentication attempt. Its getting called after 3 continues wrong authentication attempt. Is there any way to get count of wrong authentication attempts..?
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = #"Touch ID Test to show Touch ID working in a custom app";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:#"Success" sender:nil];
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:error.description
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[alertView show];
NSLog(#"Switch to fall back authentication - ie, display a keypad or password entry box");
});
}
}];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:authError.description
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[alertView show];
});
}
I went through the documentation, it is not possible to show alert in each failed attempt. Just refer the documentation
LocalAuthentication in iOS. You can show alerts at different error cases. After 3rd failed attempt LAError.authenticationFailed will be called and after 5th failed attempt LAError.touchIDLockout will be called. You can display the alerts here. For more info refer Apple LAError documentation.
I am using this code for this sharing . I update my plist with api key and also i have linked-in app on my iPhone.
I am getting success message but url not showing on linked-in page.
- (IBAction)linkedinShare:(id)sender {
NSString *url = #"http://www.tripadvisor.com";
if ([LISDKSessionManager hasValidSession])
{
[[LISDKAPIHelper sharedInstance]postRequest:url body:nil success:^(LISDKAPIResponse *response)
{
if (response)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Linkedin" message:#"Linkedin done" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
NSLog(#"Success is");
} error:^(LISDKAPIError *apiError)
{
NSLog(#"%#",apiError);
}];
I'm trying to set up an anonymous login so my users don't have to create an account an account on the eJabberd server to use the chat room. The configuration for the server in the ejabberd.cfg is:
{host_config, "bubble", [{auth_method, anonymous},
{anonymous_protocol, login_anon}]}.
My method to connect the client to the XMPPStream:
- (BOOL)connect {
[self setupStream];
if (![self.xmppStream isDisconnected]) {
return YES;
}
if (![PFUser currentUser]) {
return NO;
}
NSString *currentUserId = [NSString stringWithFormat:#"%##bubble",[PFUser currentUser].objectId];
[self.xmppStream setMyJID:[XMPPJID jidWithString:currentUserId]];
self.xmppStream.hostName = kJABBER_HOSTNAME;
NSError *error = nil;
if (![self.xmppStream connectWithTimeout:10 error:&error]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:[NSString stringWithFormat:#"Can't connect to server %#", [error localizedDescription]]
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
return NO;
}
return YES;
}
As well as the xmppStreamDidConnect method:
- (void)xmppStreamDidConnect:(XMPPStream *)sender {
self.isOpen = YES;
NSError *error = nil;
if(![self.xmppStream authenticateAnonymously:&error]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:[NSString stringWithFormat:#"Can't connect to server %#", [error localizedDescription]]
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
}
}
When I try to login into the server, it keep on getting "The server does no support anonymous authentication".
Not sure what I'm doing wrong here, please let me know your thoughts.
From the XMPPFramework documentation:
If you wish to use anonymous authentication, you should still set myJID prior to calling connect. You can simply set it to something like "anonymous#domain", where "domain" is the proper domain. After the authentication process, you can query the myJID property to see what your assigned JID is.
Make sure that the settings on the server allow anonymous login as well.
If you don't have access to the serve configuration you can still check if the server allows anonymous login using something like:
- (void)xmppStreamDidConnect:(XMPPStream*)sender
{
self.isXmppConnected = YES;
if ([self.xmppStream supportsAnonymousAuthentication]) {
NSError* error = nil;
//the server does support anonymous auth
[self.xmppStream authenticateAnonymously:&error];
}
else {
NSLog(#"The server does not support anonymous authentication");
}
}
Be sure to place it in the didConnect delegate method, as it needs to be connected first.
I'm doing a project where i use parse version 1.6.5 and localDataStore, In AppDelegate i have enabled for localDatastore like
[Parse enableLocalDatastore];
[Parse setApplicationId:#"AppId" clientKey:#"ClientKey"];
and in my ViewController i have a condition whether the app runs for firs time, if first time, retrieving from server and pin all objects to local. Else retrieve from localDatastore my code
if ([self isAppLaunchingForFirstTime]) {
PFQuery *query = [PFQuery queryWithClassName:#"Category"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
if (error) {
[[[UIAlertView alloc]initWithTitle:#"Failed!" message:#"error" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles: nil] show];
} else {
if (objects.count) {
[self.categoryArray addObject:objects];
[self.collectionView reloadData];
[PFObject pinAllInBackground:objects block:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSLog(#"Pinned successfully");
}else {
[[[UIAlertView alloc]initWithTitle:#"Error" message:#"Pinning" delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil] show];
}
}];
} else {
[[[UIAlertView alloc]initWithTitle:#"Alert!" message:#"No Records" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles: nil] show];
}
}
}];
} else {
PFQuery *query = [PFQuery queryWithClassName:#"Category"];
[query fromLocalDatastore];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
if (error) {
[[[UIAlertView alloc]initWithTitle:#"Failed!" message:error.description delegate:self cancelButtonTitle:#"Ok" otherButtonTitles: nil] show];
} else {
if (objects.count) {
[self.categoryArray addObject:objects];
[self.collectionView reloadData];
} else {
[[[UIAlertView alloc]initWithTitle:#"Alert!" message:#"No Records" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles: nil] show];
}
}
}];
}
Problem is first app runs successfully and shows the retrieved objects in collectionView whereas from second time the app has a long running background task as i'm retrieving from localDataStore it checks for network connectivity and it retries for 5 times to fetch each object. Does localDataStore requires network connectivity.
Error Log in Console :
this is the error repeatedly occurred for 36 times to fetch 7 objects.
[Error]: Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo=0x1e56e2a0
{NSErrorFailingURLStringKey=https://api.parse.com/1/classes/Category,
NSErrorFailingURLKey=https://api.parse.com/1/classes/Category,
NSLocalizedDescription=The Internet connection appears to be offline.,
NSUnderlyingError=0x1e57fae0 "The Internet connection appears to be offline."}
(Code: 100, Version: 1.6.5)
Your code should work fine. But seems that isAppLaunchingForFirstTime flag is not set off after objects successfully pinned
I suggest to report this on Parse bug report: https://www.parse.com/help#
I am using the default classes provided by app to do my networking tasks in my app.
At some point, some of my requests time out (regardless of the reason for the timeout)
I would like to retry some of these requests
I have subclassed the NSURLConnection class and added some parameters to it.
However, in the method "connection:didFailWithError:"
con.retries seems to always be 1, never incremented. Why ?
- (void)connection:(NSURLConnection*) connection didFailWithError:(NSError *)error
{
[[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
NSLog(#"%#",[NSString stringWithFormat:#"Did recieve error: %#", [error description]]);
NSLog(#"%#",[NSString stringWithFormat:#"%#", [[error userInfo]description]]);
WBURLConnection *con = (WBURLConnection *)connection;
if([con shouldRetryRequest:error]){
con.retries ++;
[con start];
}else{
[con cancel];
[con.data setLength:0];
if(!self.alert){
self.alert = [[UIAlertView alloc]initWithTitle:#"Alert" message:[error localizedDescription] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[self.alert show];
}else {
if(![self.alert isVisible]){
[self.alert show];
}
}
}
}
-(BOOL)shouldRetryRequest:(NSError *)error{
[self.retryCount appendString:[NSString stringWithFormat:#"%#:%ld",error,(long)self.retries]];
LogInfo(#"retries:%#",self.retryCount);
if([error code] == -1004){
return NO;
}
return self.retries<3;
}