Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 核心聚光灯物镜c_Ios_Objective C_Corespotlight - Fatal编程技术网

Ios 核心聚光灯物镜c

Ios 核心聚光灯物镜c,ios,objective-c,corespotlight,Ios,Objective C,Corespotlight,我正在尝试将核心聚光灯搜索添加到我的应用程序中。我已经进口了 #import <MobileCoreServices/MobileCoreServices.h> #import <CoreSpotlight/CoreSpotlight.h> 在viewDidLoad下。然后添加了以下代码 - (void)setupCoreSpotlightSearch { if ([CSSearchableIndex isIndexingAvailable]) {

我正在尝试将核心聚光灯搜索添加到我的应用程序中。我已经进口了

#import <MobileCoreServices/MobileCoreServices.h>
#import <CoreSpotlight/CoreSpotlight.h>  
在viewDidLoad下。然后添加了以下代码

- (void)setupCoreSpotlightSearch
{
    if ([CSSearchableIndex isIndexingAvailable]) {
        NSLog(@"Spotlight indexing is available on this device");
        CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString *)kUTTypeImage];

        // Set properties that describe attributes of the item such as title, description, and image.
        NSString *title = _locationTittle;
        attributeSet.title = title;
        attributeSet.contentDescription = [NSString stringWithFormat:@"%@",title];
        attributeSet.keywords = @[ title ];

        // Create an attribute set for an item

        UIImage *image = _locationImage;
        NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
        attributeSet.thumbnailData = imageData;

        // Create a searchable item, specifying its ID, associated domain, and the attribute set you created earlier.

        CSSearchableItem *item;
        NSString *identifier = [NSString stringWithFormat:@"%@",attributeSet.title];

        item = [[CSSearchableItem alloc] initWithUniqueIdentifier:identifier domainIdentifier:@"com.mybundleid.productname.search" attributeSet:attributeSet];

        // Index the item.

        [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item] completionHandler: ^(NSError * __nullable error) {
            if (!error) {
            NSLog(@"error = %@", error);

        }];
    } else {
        NSLog(@"Spotlight indexing is not available on this device");
    }
}
注意:我已将我的捆绑包id添加到。请在其后搜索

当我试图搜索地标的名称时,没有任何显示。我无法理解这一点,并尝试遵循其他教程和示例代码。有人能帮忙吗

更新。这似乎是工作,只是加载应用程序时按下,好像应用程序只是正常加载。我将它添加到我的视图控制器中,以便更详细地查看地标。这意味着用户必须单击landmark maker,它才能开始出现在聚光灯下。理想情况下,我希望它能够显示所有的地标,而不需要用户打开所有地标以便在聚光灯下显示,然后他们可以按下地标以加载特定的地标细节视图。在my view controller中,所有数据都经过处理,然后传递到地标的my detail view中的代码是这样的,它将数据传递到detail view中:

- (void)locationClicked:(ARGeoCoordinate *)coordinate{
NSLog(@"%@", coordinate);
[Answers logCustomEventWithName:coordinate.locationTittle
               customAttributes:@{}];

//user has tap on location, we need to show the location details view here
detailViewController *vc = (detailViewController*)[[self storyboard] instantiateViewControllerWithIdentifier:@"detailViewController"];
vc.locationImage = coordinate.imgLocation;
vc.locationTittle = coordinate.locationTittle;
vc.locationTxt = coordinate.locationTxt;
vc.PhotoCreditText = coordinate.photoCreditTittle;
[self.navigationController pushViewController:vc animated:YES];
}

这一切都来自:

- (NSMutableArray *)geoLocations {

NSMutableArray *locationArray = [[NSMutableArray alloc] init];
ARGeoCoordinate *tempCoordinate;
CLLocation       *tempLocation;
UIImage *locationImage;

// test locations
tempLocation = [[CLLocation alloc] initWithLatitude:53.712371 longitude:-1.882742];
tempCoordinate = [ARGeoCoordinate coordinateWithLocation:tempLocation locationTitle:@"Wainhouse Tower"];
locationImage = [UIImage imageNamed:@"WainhouseTower.jpg"];
[tempCoordinate setImgLocation:locationImage];
[tempCoordinate setLocationTxt:@"Wainhouse Tower is a folly in the parish of King Cross. At 275 feet (84 m), it is the tallest structure in Calderdale and the tallest folly in the world, and was erected in the four years between 1871 and 1875. The tower was completed on 9 September 1875, at a cost of £14,000. The main shaft is octagonal in shape and it has a square base and 403 steps leading to the first of two viewing platforms.\n\nOne driving force behind the erection of the viewing platforms was a long standing feud between Wainhouse and his neighbour, landowner Sir Henry Edwards. Edwards had boasted that he had the most private estate in Halifax, into which no one could see. As the estate was on land adjacent to the chimney's site, following the opening of the viewing platforms, Edwards could never claim privacy again.\n\nThe tower was designed by architect Isaac Booth as a chimney to serve the dye works owned by John Edward Wainhouse (1817–1883). The height of the chimney was to satisfy the Smoke Abatement Act of 1870 which required a tall chimney to carry smoke out of the valleys in which the factories were built. A much simpler chimney would have satisfied the requirements but Wainhouse insisted that it should be an object of beauty.\n\nIn 1874 John Wainhouse sold the mill to his works manager who refused to pay the cost of the chimney's construction so Wainhouse kept the tower for himself and used it as an observatory. Booth left after a dispute and was replaced by another local architect, Richard Swarbrick Dugale, who is responsible for the elaborate galleries and the corona dome at the top.\n\nThe tower is open to the public during bank holidays, and is a Grade II listed building.\n\n\nMaterial has been used from the Wikipedia article http://en.wikipedia.org/wiki/Wainhouse_Tower see that article's history for attribution.\n\nWainhouse Tower by James Preston https://flic.kr/p/cCMB2A is licensed under CC BY 2.0"];
[tempCoordinate setPhotoCreditTittle:@"See attribution below"];
[tempCoordinate setLocationTittle:@"Wainhouse Tower"];
[locationArray addObject:tempCoordinate];

return locationArray;
}

我如何使核心spotlight工作,从而不必使用上述代码为每个地标加载详细视图,当按下spotlight搜索时,它会调用上述代码?

您在哪里调用
[csSearchableIndexingAvailable]
?并非所有设备都支持CS搜索。@rmaddy Ok更新了代码。见上文。它似乎仍然不起作用。在
indexSearchableItems:completionHandler:
方法的完成块中,检查
error
是否为非零。如果非nil,则记录它。除了
NSLog(@“error=%@”,error)之外,类似于此
错误,则编码>您的
。如果(error)NSLog(“error=%@”,error),则应为
if。这样做之后,是否会记录错误?在哪里调用
[CSSearchableIndex isIndexingAvailable]
?并非所有设备都支持CS搜索。@rmaddy Ok更新了代码。见上文。它似乎仍然不起作用。在
indexSearchableItems:completionHandler:
方法的完成块中,检查
error
是否为非零。如果非nil,则记录它。除了
NSLog(@“error=%@”,error)之外,类似于此
错误,则编码>您的
。如果(error)NSLog(“error=%@”,error),则应为
if。在你这样做之后,是否会记录一个错误?
- (NSMutableArray *)geoLocations {

NSMutableArray *locationArray = [[NSMutableArray alloc] init];
ARGeoCoordinate *tempCoordinate;
CLLocation       *tempLocation;
UIImage *locationImage;

// test locations
tempLocation = [[CLLocation alloc] initWithLatitude:53.712371 longitude:-1.882742];
tempCoordinate = [ARGeoCoordinate coordinateWithLocation:tempLocation locationTitle:@"Wainhouse Tower"];
locationImage = [UIImage imageNamed:@"WainhouseTower.jpg"];
[tempCoordinate setImgLocation:locationImage];
[tempCoordinate setLocationTxt:@"Wainhouse Tower is a folly in the parish of King Cross. At 275 feet (84 m), it is the tallest structure in Calderdale and the tallest folly in the world, and was erected in the four years between 1871 and 1875. The tower was completed on 9 September 1875, at a cost of £14,000. The main shaft is octagonal in shape and it has a square base and 403 steps leading to the first of two viewing platforms.\n\nOne driving force behind the erection of the viewing platforms was a long standing feud between Wainhouse and his neighbour, landowner Sir Henry Edwards. Edwards had boasted that he had the most private estate in Halifax, into which no one could see. As the estate was on land adjacent to the chimney's site, following the opening of the viewing platforms, Edwards could never claim privacy again.\n\nThe tower was designed by architect Isaac Booth as a chimney to serve the dye works owned by John Edward Wainhouse (1817–1883). The height of the chimney was to satisfy the Smoke Abatement Act of 1870 which required a tall chimney to carry smoke out of the valleys in which the factories were built. A much simpler chimney would have satisfied the requirements but Wainhouse insisted that it should be an object of beauty.\n\nIn 1874 John Wainhouse sold the mill to his works manager who refused to pay the cost of the chimney's construction so Wainhouse kept the tower for himself and used it as an observatory. Booth left after a dispute and was replaced by another local architect, Richard Swarbrick Dugale, who is responsible for the elaborate galleries and the corona dome at the top.\n\nThe tower is open to the public during bank holidays, and is a Grade II listed building.\n\n\nMaterial has been used from the Wikipedia article http://en.wikipedia.org/wiki/Wainhouse_Tower see that article's history for attribution.\n\nWainhouse Tower by James Preston https://flic.kr/p/cCMB2A is licensed under CC BY 2.0"];
[tempCoordinate setPhotoCreditTittle:@"See attribution below"];
[tempCoordinate setLocationTittle:@"Wainhouse Tower"];
[locationArray addObject:tempCoordinate];

return locationArray;
}