What's new in IOS 9

Source: Internet
Author: User
Tags spritekit

Https://www.hackingwithswift.com/ios9

Search Extensibility

Update:i wrote a tutorial on Core Spotlight in IOS 9 as Hacking with Swift project 32–check it out!

Finally (finally!) You can hook your apps directly to Spotlight for integrated, System-wide search, and it comes in the form of Corespotlight. But don ' t get your hopes up:spotlight doesn ' t just magically index all your data while you sit back and snooze. Instead, you need-specify exactly what do you want to expose to the outside world.

What's more, Apple was specifically focusing this technology on things that's going to being directly useful to the user, so You need to is careful what do you index in Spotlight. We don ' t know how the algorithm works, but Apple have said that IOS would automatically monitor how frequently users Interac T with your search results, and if your consistently serve up unhelpful results because we indexed your data badly then yo ur results may stop appearing.

To get started, create a new instance CSSearchableItemAttributeSet of the class, then give it a title and a contentDescription . You then wrap this inside a CSSearchableItem , before passing it to the CSSearchableIndex using its indexSearchableItems method.

If a user taps on one of the your search results in Spotlight, your app would get launched with a new app delegate Callback: . If the activity type NSUserActivity CSSearchableItemActionType of the that's gets passed in matches, you can immediately direct the user to the relevant C Ontent by pulling out the CSSearchableItemActivityIdentifier key from the activity ' s userInfo dictionary.

If you prefer to read code, here's an example:

Let AttributeSet = Cssearchableitemattributeset (itemcontenttype:kuttypeimage as String) Attributeset.title = "My great Content "Attributeset.contentdescription =" This is something you'll search for. " Let item = Cssearchableitem (uniqueidentifier: "YOUR UNIQUE CONTENT IDENTIFIER Here", Domainidentifier: " Com.hackingwithswift ", Attributeset:attributeset) Cssearchableindex.defaultsearchableindex (). Indexsearchableitems ([item]) {(err:nserror?), Void in    print ("Search Item successfully indexed!")}

You'll need to the import both Corespotlight and mobilecoreservices to make the code work. You'll also need to replace ' YOUR UNIQUE CONTENT IDENTIFIER here ' with something meaningful to ' uniquely identif IES this content, so if the user launches your app as a result of doing a Spotlight search, you know .

Speaking of which, here's the code to put in your app delegate to load some content after a Spotlight search:

Func application (application:uiapplication, Continueuseractivity useractivity:nsuseractivity, RestorationHandler: ([ Anyobject]?) , Void), Bool {    if Useractivity.activitytype = = Cssearchableitemactiontype {Let        uniqueidentifier = user Activity.userinfo? [Cssearchableitemactivityidentifier]        Print ("Do stuff with \ (uniqueidentifier)")    }    return True}

Again, make sure your import corespotlight so your code compiles. Hopefully you can now see why the unique identifier are so Important–it's what's your app gets handed so you can load the C Orrect content.

There is various extensions CSSearchableItemAttributeSet to encode data such as events and maps co-ordinates, so the could prove to be one of The biggest new features in IOS 9. To see just how much information you can encode (focal length for images! Media copyright information! Contact Phone Numbe rs!) Press Shift+cmd+o and type Cssearchableitemattributeset then wait for the completions to Appear-you ' ll see media, events , images, places and more.

APP thinning

Universal Apps (aka "Fat binaries") has always meant, Apple ships a single app, that contains all the assets a nd code for it to run on any supported device. So, since the ipad launched this meant every IPhone app automatically included all the ipad imagery even though it wasn ' t Used.

When the number of supported devices is low (Non-retina IPhone and Non-retina iPad) This wasn ' t a huge problem, and if yo U were smart about your assets most of the users wouldn ' t care. But as devices has proliferated, each app now needs to include iphone retina, iphone retina HD, ipad non-retina and ipad Retina, all in the one package, even though each device would only be showing one set of assets.

Apple's solution is something developers has been asking for a long time:app thinning ensures the users download on Ly the app required to run the app on their specific device, which means an iPhone retina device (4s, 5, 5s, 6) Would download only retina assets and not retina HD devices. The Result:smaller apps, faster downloads, and happier users.

But app thinning are even cleverer, because with Xcode 7 your upload your App to iTunes Connect in a intermediate state cal LED Bitcode. When users download your app, the app Store would automatically produce an optimized version of your app (i.e., 64-bit if n eeded) to match the device, the user is using. This means they get only the assets they need and only the binary code they need, making the download even smaller.

Still think that ' s not enough? Apparently Apple agrees, because as part of the app thinning you can now host content for your apps in ITunes Connect, and requ EST It inside your app only when needed. This have been possible with In-app purchases for a few years, but being able to tag and fetch content on demand is new and Very interesting.

I wonder whether Apple is shipping app thinning now on preparation to launch an @3x Ipad–such a device would has huge I Mages, so-old school universal binaries would is more wasteful than ever.

Gameplaykit

Update:i wrote a tutorial on Gameplaykit and Gkminmaxstrategist in IOS 9 as Hacking with Swift project 34–check it out!

Update 2:i wrote a tutorial on Gameplaykit and Gkrandomsource in IOS 9 as Hacking with Swift project 35–check this out Too!

This is easily one of the most surprising changes in IOS 9, and it's rushed over so quickly in the keynote if you b Linked you probably missed it. Gameplaykit is surprising because of what it does:it ' s designed to make it easy to add high-level gameplay logic without Have to code the algorithms yourself. State machines? Done. Randomization? Check. Path finding? Got it.

To give the just how powerful Gameplaykit are, Apple have shipped demo code for a Four-in-a-row game that uses a New class called GKMinmaxStrategist . This is a class of can, under certain conditions, provide AI responses to automatically win in a game. Those conditions is pretty simple:the game must be sequential (i.e., players take turns), the game must is zero sum (one Player loses when the other wins), the game must not being based on chance, and you must being able to provide Gkminmaxstrategi St with perfect information–that are, all information required to play and win are openly visible.

Sfsafariviewcontroller

Update:i wrote a tutorial on Sfsafariviewcontroller in IOS 9 as Hacking with Swift project 32–check it out!

IOS 8 gave us WKWebView , the super-fast new to the using WebKit inside our apps, also included some UI elements such as SW Iping between the page history. IOS 9 goes one step further: SFSafariViewController is a wholly embedded Safari inside your app, exposing even + behaviour that users ha ve come to expect, such as shared cookies, AutoFill of forms, and Reader Mode.

This might seem like a strange thing to does, but think about it:lots of apps has embedded web browsers inside them, such As when you tap a link inside Twitter. But frequently these embedded web views just aren ' t as good as Safari, so-end up tapping the inevitable "Open in Safar I "button just to escape. Well, with IOS 9 is no longer needed: SFSafariViewController was a full-screen Safari user interface Controller by Apple button to return to your app.

To try it off now, you need to do four things. First, pull in the safariservices framework like this:

Import Safariservices

Second, make your view controller conform SFSafariViewControllerDelegate to the delegate, using something like this:

Class Viewcontroller:uiviewcontroller, Sfsafariviewcontrollerdelegate {

Third, create and show SFSafariViewController the, pointing at a URL of your choosing:

Let sfc = Sfsafariviewcontroller (Url:nsurl (string: "http://www.slashdot.org")!) Sfc.delegate = Selfpresentviewcontroller (SFC, animated:true, Completion:nil)

Finally, catch the delegate callback safariViewControllerDidFinish() , which is triggered when the user taps the built-in do button:

Func Safariviewcontrollerdidfinish (controller:sfsafariviewcontroller) {    Controller.dismissviewcontrolleranimated (True, Completion:nil)}

One SFSafariViewController of the neat features of is this it comes with reader mode built in, and you can actually navigate straight to th At view by using the This code:

Let sfc = Sfsafariviewcontroller (Url:nsurl (string: "http://www.slashdot.org")!, Entersreaderifavailable:true)
Uistackview

Update:i wrote a tutorial on Uistackview and IPad multitasking in IOS 9 as Hacking with Swift project 31–check it out!

Android developers has a long had a layout system called LinearLayout, where you add views to a superview and they automati Cally get placed either beneath each other or side by side. We Haven ' t really had a good solution like this on ios–table views is greatly at stacking information vertically, but a Re of course hugely limited in terms of their content.

With UIStackView , that's all changed:you can now add a series of views to a Superview, specify what much spacing you want betwee n them, and Auto Layout handles the rest for you. You get to choose whether-want the subviews to has equal sizes ( .FillEqually ) or proportional sizes ( .FillProportionally ) based on their I Ntrinsic content sizes. You can also choose whether your want the subviews to fill horizontally or vertically, and you can change your mind later.

Important Note: UIStackViews don ' t Scroll, they just act as containers that automatically fit their content.

Uicollectionviews can now behave more like uitableviews

With one simple Boolean property for UICollectionViewFlowLayout , you can now make your flow layout work the same-a- sectionHeadersPinToVisibleBounds UITableView has Always done:your sections headers stick to the top of the "screen" while the "User is scrolling inside", and only Get pushed off when the next section is comes in. The overdue, but at least it's here now.

Uicollectionviews now has easy re-ordering

Set the property to installsStandardGestureForInteractiveMovement true on your and give users, the ability to UICollectionViewController re-order your items.

Skaudionode

One of the major SpriteKit annoyances have been its simplistic audio system. In IOS 8, for example, you can play sounds but not stop them, and heaven forbid if you want to control the sound in any WA Y. Well, in IOS 9 we had to the SKAudioNode Rescue:not only can you pause and stop sounds (hurray!) If you can also set its p Ositional property to True to has its sound adjusted based on the node's position in your scene. Yes:spritekit now has 3D audio.

Lots of tiny changes

One of my favorite things to does when Apple flicks the switch on a new IOS release are to read through the complete list of API changes, looking for all the tiny improvements and tweaks Apple makes each year. Here is some of the changes that jumped off to me this year:

    • Uiviewcontroller now have an addKeyCommand() method to register Uikeycommands in your view Controllers–manna from heaven for users of external keyboards.
    • MKMapView.showsTraffic: Set it to true, and it, er, shows the traffic. Simple, but such a huge feature to has.
    • CIFeatureTypeTextSounds like Apple added some sort of OCR to IOS, but sadly it just gives you the bounds where text is located. It's a step forward, but only a small one.
    • Just look at avfoundation. Go on, look at it and cry tears of joy.

What's new in IOS 9

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.