I am trying to do search functionality in iPhone. I pass the page number and the string to be searched.. but it is not getting the proper output.
in contentStream I get nothing. I got this code by googling. I don't know what will be there in contentStream object.
-(BOOL)page:(CGPDFPageRef)inPage containsString:(NSString *)inSearchString {
[self setCurrentData:[NSMutableString string]];
CGPDFContentStreamRef contentStream = CGPDFContentStreamCreateWithPage(inPage);
CGPDFScannerRef scanner = CGPDFScannerCreate(contentStream, table, self);
bool ret = CGPDFScannerScan(scanner);
CGPDFScannerRelease(scanner);
CGPDFContentStreamRelease(contentStream);
return ([[currentData uppercaseString]
rangeOfString:[inSearchString uppercaseString]].location != NSNotFound);
}
If there is any other solution then also it is fine.
YOU SHOULD IMPLEMENT THE COMPLETE CODE
http://www.random-ideas.net/posts/42%22
check out the above link
a complete code to do so.
Check out this question and its answers for more information: PDF search on the iPhone
Related
Preamble: I'm working with some code I didn't write and I have next to no knowledge of iOS.
The app has a webview which handles most of the app; internal links are loaded in the webview and links to other sites are opened in Safari which is expected. However, embedding a google maps also causes safari to open. I found the relevant controller code, I think, and it looks like this:
// a bit higher up
static NSString *const siteURL = #"http://my.example.com"
if (![request.URL.absoluteString hasPrefix:siteUrl])
{
if ([[UIApplication sharedApplication] canOpenURL:request.URL])
{
[[UIApplication sharedApplication] openURL:request.URL];
}
return NO;
}
Now because 'maps.google.com' doesn't start with 'my.example.com' it farms out to safari - and that makes sense to me. However, I tried modifying this:
static NSString *const googleMaps = #"http://maps.google.com"
if (! ([request.URL.absoluteString hasPrefix:siteUrl] || [request.URL.absoluteString hasPrefix:googleMaps]))
{
if ([[UIApplication sharedApplication] canOpenURL:request.URL])
{
[[UIApplication sharedApplication] openURL:request.URL];
}
return NO;
}
This also works. But I need to add some more URLs. Is my only choice to keep adding 'or' and string constants? Or is there a way to make an array and say "if it matches any of these"? Sorry if this question seems simplistic.
In PHP I'd just do something like in_array('string', $array) as my condition, I guess I'm looking for how to do this in iOS
One solution would be to maintain a NSSet of objects, being all the strings that you want to be handled in your internal webview.
NSSet *internalURLSet = [NSSet setWithObjects:#"http://my.example.com", #"http://maps.google.com", nil];
Use a mutable set if you will be adding to the set over time but you will likely know which URLs you want to handle internally as soon as your app starts and this will not change. If you are adding sets as the app runs then add them to the mutable set as they become known.
When you check a URL, use [internalURLSet containsObject:urlToTest] and it will match any of the strings you have added to the set.
Checking against the set is very efficient. Adding objects to the set is less so, but you will very likely add URLs to the set only once while you check many times.
(Doing indexOfObject: against a NSArray is very inefficient...)
You could try using a predicate. Here's a tutorial link with an example (older, but should still work):
http://arstechnica.com/apple/2009/04/cocoa-dev-the-joy-of-nspredicates-and-matching-strings/
I do a lot of .NET development too and always miss LINQ when I go back to iOS. Predicates help a little, more lines of code but handy since you can do all kinds of searches.
I see your problem. In IOS, don't have a function in_array('string',$array) to check a string is contained in array.
I have a suggestion: you create a array with all urls. And implement 'for' or 'while' loop to get value of array check it. If it's same, you call function OpenUrl.
You could do this by creating an NSArray of your URLS and then using the indexOfObjectPassingTest: method to test your URL against each one in the array. It would go something like this:
NSArray *testURLs = #[ #"http://maps.google.com", #"http://www.example.com" ];
NSString *urlString = request.URL.absoluteString;
BOOL urlMatchedTest = NO;
for ( NSString *testURL in testURLs ) {
if [urlString hasPrefix:testURL] ) {
urlMatchedTest = YES;
}
}
if ( urlMatchedTest ){
// the url contains one of the test URLS
} else {
// it didn't match any of the test URLs
}
I use Zxing library for Barcode, QRCode and Data matrix scanning. scanning process is work fine.
I also get result string from didScanResult delegate method of ZXingWidgetController.
- (void)zxingController:(ZXingWidgetController*)controller didScanResult:(NSString *)result {
}
But I have one problem...
how to get type (Text, URL, Address book, Phone Number, Email address etc..) and format (QRCode, Data matrix or Barcode) of result.
please help...
and thanks in advance...
Assuming that currently you are using ZXingWidget right?
Since there is no way to get barcode format in this library. So what i have done is i replaced this library with ZXingObjC library to get barcode type as well as format.
-(void)captureResult:(ZXCapture *)capture result:(ZXResult *)result
{
if (!result) return;
// We got a result. Display information about the result onscreen.
NSString *formatString = [self barcodeFormatToString:result.barcodeFormat];
NSString *display = [NSString stringWithFormat:#"Scanned!\n\nFormat:
%#\n\nContents:\n%#", formatString, result.text];
}
In text field when user start typing the location name, i want to show the list of locations name below as the user type, similar to search field like starts with alphabet 'A' show all option of 'A'. How can this be achieved.
How can I get location names?
Please guide for the above. And if any other thing need to ask please feel free to ask.
Thanks in advance.
You need to use google api for that for sure.. Here is a link: https://developers.google.com/places/documentation/autocomplete
The Google Places Autocomplete API is a web service that returns Place information based on text search terms, and, optionally, geographic bounds. The API can be used to provide autocomplete functionality for text-based geographic searches, by returning Places such as businesses, addresses, and points of interest as a user types.
You need to create your API Key using https://code.google.com/apis/console/#project:18836829369. When you get your response you just need to look at predictions in your json response.
Hope this helps :)
You Should use google place API. I dont know much about that but this link will be helpful.
Remember this for location search not for autocomplete searchbar.
You can use the below given function :
- (void)searchText:(NSString *)substring
{
for (int i = 0; i < [yourArray count]; i++)
{
NSString *curString = [[yourArray objectAtIndex:i]lowercaseString];
NSString *searchString = [substring lowercaseString];
if ([curString rangeOfString:curStringSmall].location == NSNotFound)
{
}
else
{
//This means searched text is found in your array. you can store it in new array. Which will give you only the search criteria matched element.
}
}
}
You need to call this function from textFieldShouldBeginEditing :
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[self searchText:txtSearch.text];
return YES;
}
typedef struct _protocol1
{
int type;
CGPoint pos;
} Protocol1;
-(void)sendData {
NSError *error;
Protocol1 msg;
msg.pos = ccp(100,100);
msg.type = 1;
NSData *packet = [NSData dataWithBytes:&msg length:sizeof(Protocol1)];
[self.myMatch sendDataToAllPlayers: packet withDataMode: GKMatchSendDataReliable error:&error];
if (error != nil)
{
NSLog(#"error"]);
}
}
That is a chunk of code from my project.
And I'm getting an error. However, I am unsure how to retrieve more information to help me debug. Can someone help me?
Sorry, I'm quite new with iOS development...
Using Cocos2d for a game.
EDIT
I am using the Simulator and my iPhone to test this. I doubt that is the problem, I already got the match working and everything...
To print out your error, try this!
NSLog(#"here is the error material: %#", [error localizedDescription])
if you have trouble, just click on NSError in your XCode4.
Then look at the right column, and click to get to the documentation.
(Or just search "NSError" in the Xcode documentation.)
Bring up "NSError Class Reference". It is very simple.
Be sure to look at the VARIOUS EXAMPLE CODE given.
For example scroll down to "localizedDescription" ad see the three sample codes. ("LazyTableImages, SeismicXML, URLCache")
You can download and look at the example projects. Search on "localizedDescription" and you'll see examples, if you're having trouble!
If you teach a man to fish ... Lol have fun.
i want to get data between xml tags? how to navigate? and get values..
im using wsdl2objc from google code:http://code.google.com/p/wsdl2objc/
output soapbody follows:
read instruction here: http://code.google.com/p/wsdl2objc/wiki/UsageInstructions
my header file: #import "MService.h"
how to get image source and text value????
please help me....
if([bodyPart isKindOfClass:[types_getFavoriteColorResponseType class]]) {
types_getFavoriteColorResponseType *body = (types_getFavoriteColorResponseType*)bodyPart;
// Now you can extract the color from the response
q.text = body.color;
continue;
}
Ок as far as I understand this is a part which extracts text data from your SOAP response.
BTW you need response to be processed via SAX or DOM? First example in given URL refers to DOM usage, whereas the second to SAX.
More than that I can not tell. Guess you have to read manual or find someone, who worked with this.
Use NSXMLParser, NSXMLParserDelegate for xml parsing, you can get the callbacks with proper values:
parser:didStartElement:namespaceURI:qualifiedName:attributes:
parser:foundCharacters:
parser:didEndElement:namespaceURI:qualifiedName:
Ref: http://developer.apple.com/library/ios/#documentation/cocoa/reference/NSXMLParserDelegate_Protocol/Reference/Reference.html
hey i got the result using sudzc.com
if ([result isKindOfClass:[MSalesPages class]]) {
NSLog(#"Response");
NSMutableArray* pageData = result.PageData;
for(MSalesPage* page in pageData){
NSLog(#"Inside for loop %#", page.Id);
NSMutableArray* images = page.Images;
NSMutableArray* textData = page.TextData;
for(MSalesImg* img in images){
NSLog(#"Image url %#",img.Src);
}
for(MSalesText* text in textData){
NSLog(#"Product Name %#",text.Value);
}
}
}
carefully check with the above xml, u will get the answer :)