CoreSpotlight Thumbnail Image not showing up on Spotlight search - ios

I am trying to make my in app content searchable with help of Core Spotlight. Everything works great, title and description comes but without thumbnail.
here is what I am trying:
CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc]initWithItemContentType:(NSString *)kUTTypeImage];
attributeSet.title = #"My First Spotlight Search";
attributeSet.contentDescription = #"This is my first spotlight Search";
attributeSet.keywords = [NSArray arrayWithObjects:#"Hello", #"Welcome",#"Spotlight", nil];
UIImage *image = [UIImage imageNamed:#"searchIcon.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
attributeSet.thumbnailData = imageData;
CSSearchableItem *item = [[CSSearchableItem alloc]initWithUniqueIdentifier:#"com.deeplink" domainIdentifier:#"spotlight.sample" attributeSet:attributeSet];
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:#[item] completionHandler: ^(NSError * __nullable error) {
if (!error)
NSLog(#"Search item indexed");
}];

The iOS 9 beta 1 release notes state that thumbnails aren't yet working for search results. See: https://developer.apple.com/library/prerelease/ios/releasenotes/General/RN-iOSSDK-9.0/index.html

Related

Set title property from NSarray in CSSearchableItemAttributeSet

I am trying to using CoreSpotlight API in application , I have plist file which has a several items on it for example animals' name . So I need to set title string equal to on of those object , for example if users search Lion , the line name and for example its features appears on the spotlight . Here is my code :
- (void)setupCoreSpotlightSearch
{
CSSearchableItemAttributeSet *attibuteSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(__bridge NSString *)kUTTypeImage];
NSURL *url = [[NSBundle mainBundle] URLForResource:#"animals" withExtension:#"plist"];
NSArray *playDictionariesArray = [[NSArray alloc ] initWithContentsOfURL:url];
NSString *getNames = [NSString stringWithFormat:#"%#",playDictionariesArray];
NSLog(#"%#",getNames) ;
attibuteSet.title =getNames;
attibuteSet.contentDescription = #"blah blah ";
CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:#"app name"
domainIdentifier:#"com.compont.appname"
attributeSet:attibuteSet];
if (item) {
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:#[item] completionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(#"Search item indexed");
}
}];
}
}
The problem is getNames returns all names !!! how can I filter it when is user is searching an specific word from animals.plist
Thanks .
EDIT [Plist Image]:
You can maintain NSArray and iterate through playDictionariesArray, creating & initialising CSSearchableItem object with that particular entry in your data source.
- (void)setupCoreSpotlightSearch
{
NSURL *url = [[NSBundle mainBundle] URLForResource:#"animals" withExtension:#"plist"];
NSArray *playDictionariesArray = [[NSArray alloc ] initWithContentsOfURL:url];
NSMutableArray * searchableItems = [[NSMutableArray alloc]init];
for(object in playDictionariesArray)
{
CSSearchableItemAttributeSet *attibuteSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(__bridge NSString *)kUTTypeImage];
attibuteSet.title =[NSString stringWithFormat:#"%#",object]; //retrive title from object and add here
//attibuteSet.contentDescription = #"blah blah "; // retrieve description from object and add here
CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:#"app name"
domainIdentifier:#"com.compont.appname"
attributeSet:attibuteSet];
[searchableItems addObject:item];
}
if (searchableItems) {
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:searchableItems completionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(#"Search item indexed");
}
}];
}
}
I haven't ran and tested the code.
you are not looping through each key. Use the code provided in this question.
CoreSpotlight indexing
Try it on a device that supports indexing.
NOT iPhone 4/4s or iPad.

BAD_ACCESS when calling CSSearchableIndex indexSearchableItems

I am trying to implement the CoreSpotlight API in my app but can't seem to figure out why I am getting a BAD_ACCESS exception with my implementation:
CSSearchableItemAttributeSet * attributeSet = [CSSearchableItemAttributeSet new];
attributeSet.title = route.Options.name;
attributeSet.keywords = [route.Options.name componentsSeparatedByString:#" "];
UIImage *image = [UIImage imageNamed:#"pin_busstop.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
attributeSet.thumbnailData = imageData;
CSSearchableItem * item = [[CSSearchableItem alloc] initWithUniqueIdentifier:route.ObjectID domainIdentifier:#"com.whatever.itsmyappsname.loadwithroute" attributeSet:attributeSet];
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:[NSArray arrayWithObject:item] completionHandler:^(NSError * _Nullable error) {
NSLog(#"It worked");
}];
Looking at the call stack for the exception, I can see that it occurs on the CSSearchableIndex indexSearchableItems: completionHandler: call. However I can step past that call without the exception triggering, maybe it has to do with the completion handler, however it happens regardless of if I have one or not. I have CoreSpotlight/CoreSpotlight.h and MobileCoreServices/MobileCoreServices.h imported both in my .h file and in the target.
You're (I'm) creating the CSSearchableItemAttributeSet object incorrectly. Instead of:
CSSearchableItemAttributeSet * attributeSet = [CSSearchableItemAttributeSet new];
Use:
CSSearchableItemAttributeSet * attributeSet = [[CSSearchableItemAttributeSet alloc]
initWithItemContentType:(NSString *)kUTTypeImage];

Getting images from the XML Links

http://www.cinejosh.com/news/3/40889/high-court-dismisses-andhra-poris-case.html
In above link I have this tag
<img src="/newsimg/newsmainimg/1433410900_andhra-pori.jpg" alt="High Court Dismisses 'Andhra Pori's Case" class="img-responsive center-block visible-xs">
I have the above tag and I need to get the image on imageview.
My code is like this
NSString *gossipsXpathQueryString = #"//td//img";
//imageGossipsNodes is the array to get data
imageGossipsNodes = [gossipsParser searchWithXPathQuery:gossipsXpathQueryString];
for (TFHppleElement *element in imageGossipsNodes)
{
NSString *imageUrlString = [NSString stringWithFormat:#"http://www.cinejosh.com%#", [element objectForKey:#"src"]];
}
Now I want to pass the string for getting images.How to achieve this?Please help me.
Thanks
You have two options Synchronous and Asynchronous options. Try to use async methods.
UIImage *image = [UIImage imageWithContentsOfURL:[NSURL URLWithString:imageUrlString];
yourImageView.image = image;
or
dispatch_async(dispatch_get_global_queue(0,0), ^{
NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:imageUrlString];
UIImage *image = [UIImage imageWithData: data];
dispatch_async(dispatch_get_main_queue(), ^{
yourImageView.image = image;
});
});

Display Image Through New Parse Config

So I am using the new Parse Config for my application. The easy part was the installation of the NSString, but now I am working on the ImageView. Can someone help me figure out how to execute this?
Here is how I am calling for a NSString:
[PFConfig getConfigInBackgroundWithBlock:^(PFConfig *config, NSError *error) {
NSNumber *number = config[#"numberOne"];
textLabel.text = [number stringValue];
}];
Now I have created an Image called mainImage and I need this to set to mainImageFile from my Parse server. This is where I got stuck:
[PFConfig getConfigInBackgroundWithBlock:^(PFConfig *config, NSError *error) {
PFFile *pfFileMainImage = config[#"mainImageFile"];
//
//
}];
If this helps.. This is how I would set the images from Parse in tableView:
PFFile *thumbnail = [object objectForKey:#"imageFile"]; PFImageView
thumbnailImageView = (PFImageView)[cell viewWithTag:100]; thumbnailImageView.image = [UIImage
imageNamed:#"add-photo-placeholder.png"]; thumbnailImageView.file =
thumbnail; [thumbnailImageView loadInBackground];
Thank you!

Inserting Images in Specific Album on Picasa in iOS

I am working with an iOS application in which i upload images on Picasa web albums from my iOS application.When i create album firstly i check whether any album with the same name exist or not so i fetch all the albums with their name and album id with the below code.
for (GDataEntryPhotoAlbum *albumEntry in feed)
{
NSString *title = [[albumEntry title] stringValue];
NSString *title1 = [albumEntry GPhotoID];
NSLog(#"File Title: %# | ID: %#",title,title1);
}
i get all the album name and albumid .
now i check with the current album name given by the user.
if ([title isEqual:albumName]){
//do not create new album
// return the album id
}
else{
//create new album
}
Everything working fine ,but now the problem is how can i send the albumid to the uploading method which is below mentioned:
- (void)_startUpload:(UIImage *)image:(NSString *)filePath{
NSLog(#"album feed is %#",albfeed);
// user/11106615845/albumid/6029121 gphotoID:60291215413
//GDataFeedPhotoAlbum *albumFeedOfPhotos = [self photoFeed];
//https://photos.googleapis.com/data/upload/resumable/media/create-session/feed/api/user/114789383162963173862/albumid/6025392474120084449
//https://photos.googleapis.com/data/entry/user/1082642086705/albumid/60254095886065
NSURL *uploadURL1 = [[[albfeed uploadLink] URL] retain];
NSString *photoPath = [[NSBundle mainBundle] pathForResource:#"red_bull" ofType:#"jpg"];
NSString *photoName = [photoPath lastPathComponent];
NSLog(#"uploadURL1 : %#",uploadURL1 );
NSLog(#"photoPath : %#",photoPath);
NSLog(#"photoName : %#",photoName);
NSData *photoData = [NSData dataWithContentsOfFile:filePath];
if (photoData) {
GDataEntryPhoto *newEntry = [GDataEntryPhoto photoEntry];
[newEntry setTitleWithString:photoName];
[newEntry setPhotoDescriptionWithString:filePath];
[newEntry setTimestamp:[GDataPhotoTimestamp timestampWithDate:[NSDate date]]];
[newEntry setPhotoData:photoData];
NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:filePath
defaultMIMEType:#"image/jpeg"];
[newEntry setPhotoMIMEType:mimeType];
[newEntry setUploadSlug:photoName];
GDataServiceGooglePhotos *service = [self googlePhotosService];
SEL progressSel = #selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
service.authToken = authTokens;
[service setServiceUploadProgressSelector:progressSel];
GDataServiceTicket *ticket;
ticket = [service fetchEntryByInsertingEntry:newEntry
forFeedURL:uploadURL1
delegate:self
didFinishSelector:#selector(addPhotoTicket:finishedWithEntry:error:)];
[service setServiceUploadProgressSelector:nil];
}else {
NSLog(#"### Image not loaded");
}
i don't know how will i send the specific albumid so that i don't need to create a new album ,if that album is already found in my account.
How can i achieve that??
I don't want to create another album with the same name,,get the albumid and upload images on the previous album.
please help me out.
Thank you for your precious time.

Resources