ios - Use NSUserActivity and CoreSpotlight but still set iOS8 as Deployment Target -
is possible use new features of ios9 such nsuseractivity , corespotlight, still set development target 8.2 users ios8 can still use app?
i assume need ios version number check or use respondstoselector:.
is correct?
yes, in 1 of apps (actually have deployment target of ios 7). it's trivial do. make sure cssearchableindex class exists, make corespotlight framework optional, , write code prevent newer apis being run on devices earlier versions of ios.
you can guard code compiles under xcode 6 if had reason so.
example:
// ensure compiles base sdk of ios 9 or later #if __iphone_os_version_max_allowed >= 90000 // make sure class available , 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 index core spotlight }); } #endif in app delegate:
#if __iphone_os_version_max_allowed >= 90000 - (bool)application:(uiapplication *)application continueuseractivity:(nsuseractivity *)useractivity restorationhandler:(void(^)(nsarray *restorableobjects))restorationhandler { if ([[useractivity activitytype] isequaltostring:cssearchableitemactiontype]) { // activity represents item indexed using core spotlight, restore context related unique identifier. // unique identifier of core spotlight item set in activity’s userinfo key cssearchableitemactivityidentifier. nsstring *uniqueidentifier = [useractivity.userinfo objectforkey:cssearchableitemactivityidentifier]; if (uniqueidentifier) { // process identifier needed } } return no; } #endif
Comments
Post a Comment