How to disable skype call button in webview, when the user is offline?
Asked Answered
N

2

6

I use Skype integration in my iPhone app by using html. When i load a page it will show whether the user will be online or offline. When i press ONLINE button my app will be closed and Skype will be open. But, when i press OFFLINE button it will happen the same thing like that above.. I used the following code for designing skype button in webview to show the skype online status of user and for skype calling.

<a href="skype:arafa_futbal?call">
<img src="http://mystatus.skype.com/smallclassic/arafa_futbal" style="border: none;"
width="114" height="20" alt="My status" />
</a>

My question is how can i disable the webview when the user is offline?

ie,If i press the OFFLINE button, it shouldn't do anything..

Nelly answered 14/11, 2012 at 7:11 Comment(0)
E
0

This will solve ur problem. Call the url http://mystatus.skype.com/arafa_futbal.xml in nsurlconnection and get the xml data and parse it to get the user skype status

NSURL *url = [NSURL URLWithString:@"http://mystatus.skype.com/arafa_futbal.xml"stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:0 forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"GET"];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn) {
webData = [[NSMutableData data] retain];
}

-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
  [webData setLength:0];
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
  [webData appendData:data];
}

-(void) connectionDidFinishLoading:(NSURLConnection *) connection {
xmlParser = [[NSXMLParser alloc] initWithData:webData];
[xmlParser setDelegate:self];
[xmlParser setShouldResolveExternalEntities:YES];
 [xmlParser parse];
}
-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
}

-(void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
   if ([string isEqualToString:@"Offline"]) 
   {
     webview.userinteractionEnabled = NO;
   }
   if ([string isEqualToString:@"Online"]) 
   {
     webview.userinteractionEnabled = YES;
   }
 }
Epizootic answered 14/11, 2012 at 13:57 Comment(0)
W
1

Do you have control over the HTML? If so, use http://mystatus.skype.com/arafa_futbal.xml to decide whether to create a Skype link or not.

One caution: I don't know if I've always had "Allow my online status to be shown on the web" unchecked, or if that was the default, but it doesn't work for me unless I turn that on under the "Privacy" settings.

If you don't have control over the HTML, it's not something I'd know how to do with a UIWebView.

Worn answered 14/11, 2012 at 9:14 Comment(0)
E
0

This will solve ur problem. Call the url http://mystatus.skype.com/arafa_futbal.xml in nsurlconnection and get the xml data and parse it to get the user skype status

NSURL *url = [NSURL URLWithString:@"http://mystatus.skype.com/arafa_futbal.xml"stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:0 forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"GET"];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn) {
webData = [[NSMutableData data] retain];
}

-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
  [webData setLength:0];
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
  [webData appendData:data];
}

-(void) connectionDidFinishLoading:(NSURLConnection *) connection {
xmlParser = [[NSXMLParser alloc] initWithData:webData];
[xmlParser setDelegate:self];
[xmlParser setShouldResolveExternalEntities:YES];
 [xmlParser parse];
}
-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
}

-(void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
   if ([string isEqualToString:@"Offline"]) 
   {
     webview.userinteractionEnabled = NO;
   }
   if ([string isEqualToString:@"Online"]) 
   {
     webview.userinteractionEnabled = YES;
   }
 }
Epizootic answered 14/11, 2012 at 13:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.