HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用NSUserActivity和CoreSpotlight但仍将iOS8设置为部署目标大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
是否可以使用iOS9的新功能,如NSUserActivity和CoreSpotlight,但仍然将我的开发目标设置为8.2,以便iOS8的用户仍然可以使用该应用程序?

我假设我只需要进行iOS版本号检查或使用respondsToSELEctor:.

它是否正确?

解决方法

是的,我在我的一个应用程序中执行此操作(实际上具有iOS 7的部署目标).做起来很简单.只需确保CSSearchableIndex类存在,使CoreSpotlight框架可选,并正确编写代码以防止较新的API在具有早期版本iOS的设备上运行.

您甚至可以保护代码,以便在有充分理由的情况下在Xcode 6下进行编译.

例:

// Ensure it only compiles with the Base SDK of iOS 9 or later
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
    // Make sure the class is available and the device supports CoreSpotlight
    if ([CSSearchableIndex class] && [CSSearchableIndex isIndexingAvailable]) {
        dispatch_async(_someBGQueue,^{
            NSString *somename = @"Some Name";
            CSSearchableIndex *index = [[CSSearchableIndex alloc] initWithName:somename];
            // rest of needed code to index with Core Spotlight
        });
    }
#endif

在您的app委托中:

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
- (BOOL)application:(UIApplication *)application conTinueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray *restorabLeobjects))restorationHandler {
    if ([[userActivity activityType] isEqualToString:CSSearchableItemActionType]) {
        // This activity represents an item indexed using Core Spotlight,so restore the context related to the unique identifier.
        // The unique identifier of the Core Spotlight item is set in the activity’s userInfo for the key CSSearchableItemActivityIdentifier.
        NSString *uniquEIDentifier = [userActivity.userInfo objectForKey:CSSearchableItemActivityIdentifier];
        if (uniquEIDentifier) {
            // process the identifier as needed
        }
    }

    return NO;
}
#endif

大佬总结

以上是大佬教程为你收集整理的使用NSUserActivity和CoreSpotlight但仍将iOS8设置为部署目标全部内容,希望文章能够帮你解决使用NSUserActivity和CoreSpotlight但仍将iOS8设置为部署目标所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。