What is an ARKit? AR - Augmented Reality. ARKit is Apple’s framework for AR apps and games. It is a developers tool that user don't need to worry about. It is a development platform used by the developers of an iOS app development company. Overview The ARKit library was introduced by Apple in WWDC 2017. It allows the developers to build apps using the AR (Augmented Reality) technology. ~ AR apps allow us to view virtual objects in the real environment through the camera. ~ AR describes user experience that adds 2D or 3D elements to the live view from a device’s camera in a way that makes those elements appear to inhabit the real world. ~ For a 2D object, SpritKit Library is used. For 3D Objects, SceneKit is used. ~ With 2D AR, you can add overlays or signposts, which respond to geographic location or visual features in real-time or with 3D AR, you can visualize how a painting might look in the walls of your living room or on the walls of your without you having to leave your home. ~ At WWDC 2018, Apple released ARKit 2.0 with a slew of brands new APIs and features for Augmented Reality Development. ~ ARKit uses device’s motion sensors combined with visual information from the camera to track the real world. Some clever math uses this tracking data and maps specialties into the real 3D world to your 2D screen. What’s new in ARKit 2? ARKit has some new additions that have made it a lot better and fun to use. Developers have new options to add in their developments. Let’s take a look at the developments in ARKit2. Realistic Rendering The interpretation of augmented reality objects is already quite good. However, Apple has improved rendering. ARKit 2 unlocks the ability for museums or similar organizations to “scan” their exhibition and allow information panels to appear above the statue. 3D Object Detection and Tracking ARKit 1.5 adds support for 2D image identification, letting you trigger an AR experience based on 2D images like posters, artwork or signs. ARKit 2 gave this support to offer full 2D image tracking, so you can include movable objects like product boxes or magazines into your AR experiences. ARKit 2 also adds the capability to identify familiar 3D objects like sculptures, toys or furniture. Persistent Experiences You can keep AR spaces and objects that are connected to the physical objects (like toys) or physical spaces (like classrooms), so you can choose up where you left off last time. According to Apple’s description, a world map comprises of anchors, objects and other features that an ARKit uses to be aware of the space around the user. ARKit 2 brings the ability to endure these world maps, which opens the ability to yield these experiences with others or save them for use in the same application later. Shared Experiences Many users will be able to use their iOS devices to see the identical virtual environment, each from their own view. Apple is releasing a block-breaking multiplayer game as a code demand demo and Logo showed off a virtual play space where up to four players can interact with a merged virtual and real play space altogether. USDZ Format Apple worked with Pixar to create a new file format for augmented reality objects called USDZ. This will be supported by third-party apps including ones by AutoDesk, Adobe, Sketchfab and more. USDZ is a new file format used to display and share 3D content natively in iOS, with optimizations for storage and sharing. On iOS 12, a built-in app such as Safari, Messages, Mail, News and Notes can natively Quick Look USDZ files of virtual objects in 3D or AR. Environment Texturing Environment textures are cube-map textures that depict the view in all directions from a specific point in a scene. In 3D asset interpretation, environment textures are the basis for image-based lighting algorithms where the surface can practically reflect light from their surroundings. Arkit can generate environment textures during an AR session using camera imagery, allowing SceneKit or a custom rendering engine to provide realistic image based lighting for virtual objects in your AR experience. When using augmented reality, it’s necessary to make objects combine with the environment around them. In the first version of ARKit, highlights such as ambient light detection tried to make the virtual object “fit in” with the scene. ARKit 2 allows the object to reveal the texture around them. The ARKit apps will be using SceneKit for its interpretation. SceneKit is the native 3D rendering engine for iOS, with direct hooks into ARKit. Requirement There are a few requirements for using ARKit. 1. Processor An A9 or later processor: Only the iPhone 6s and up, the 2017 iPhone and iPad Pros can run ARKit. 2. Space You will need plenty of space. To play ARmageddon, you will need clear space so you can capture bugs without falling over your furniture. 3. Contrast If your room has white tiles, furniture and walls, or maybe it is too dark, things won’t work too well; the camera requires a contrast in order to identify surfaces and distances of objects. 3D model format 3D Models are of the format DAE and SCN We can create a customize 3D models using the free Blender Software. There are a few native formats available in SceneKit that we can use to load the 3D Model. The DAE format allows us to have multiple objects in the scene file, including cameras and lights as well as any geometry. Sizing and Units SceneKit makes use of meters as a unit of measurement for sizing and physics simulations. So when there is a mention of size, including the Scene Editor in Xcode, it is always in context to meters. In Blender, you also need to ensure you’re working in meters. Blender’s default is a meter unit, but it’s always safer to check than deal with a giant or minuscule model in your scene. Coordinate System SceneKit operates in a “Y-up” system, meaning the Y-axis is pointing up, whereas Blender works with the Z-axis pointing up. We should have knowledge of this before exporting our scene and when loading it into SceneKit. Usually, this isn’t a problem, as the exporter normally takes care of the conversion. Depending on whether you’re using a custom exporter or are working in a different coordinate system, you may need to rotate the model inside of your modeling application. How World Tracking Works To create a correspondence between real and virtual spaces, ARKit uses a technique called visual-inertial odometry. This process combines information from the iOS device’s motion-sensing hardware with the computer vision analysis of the scene visible to the device’s camera. ARKit recognizes notable features in the scene image, tracks differences in the positions of those features across video frames, and compares that information with motion sensing data. The result is a high-precision model of the device’s position and motion. World tracking also examines and interprets the contents of the scene. Use hit-testing techniques to find the real-world surfaces matching to a point in the camera image. If you enable the Plane Detection setting in your session configuration, ARKit identifies flat surfaces in the camera image and communicates their position and sizes. You can use hit-test results or identified planes to place or communicate with virtual content in your scene. Conclusion In this article, we have covered points about what’s new in ARKit, its Format, Coordinate system, etc. With these new formats and features, we can move our application to the Next Level of the current world environment. These features will benefit the developers of a Mobile app development company allowing them to advance their apps. Happy Coding! and feel free to share your own experience on “[email protected]”.
With time technology is moving fast too. This article will provide information about Xcode 10 tool and what is new in Xcode 10 compared to its earlier version. It is beneficial for the developers who like to add new features to their apps. Our experts use the latest tools & technologies to deliver the best to our clients. Xcode 10 is one of the tools we used after thorough testing. 9series always ensures to test all the tools before they use it for your solutions. Below is the synopsis of the blog in case you just want an overview of the same ~ Xcode 10 was announced at WWDC 2018 on 4 June 2018. ~ Xcode 10 includes Swift 4.2 and SDKs for iOS 12, watchOS 5, tvOS 12, and macOS 10.14. ~ Xcode 10 requires a Mac running macOS 10.13.4 or later. ~ It is capable of running multiple simultaneous versions of the Xcode App and any associated tools. The interesting thing about Xcode 10 is that it can coexist with the previous version. Here are the detailed of the new features. Dark Mode ~ Xcode now supports the Dark Mode. You can adopt a dark mode instead of wide light as the appearance. It is a system-wide appearance that is already implemented and adopted by many apps. ~ Dark mode is now available in the Xcode 10. Xcode 10 also enables you to create your own dark apps for macOS. You can also move between the light and dark mode. You can also move your app in and out of Dark mode while debugging. Better Editor Xcode 10 supports multi-line editing by selecting multiple lines. If we want to change all functions to private functions, then we can select all lines of func and replace them with private functions. New Build System ~ The new build system has been activated by default in Xcode 10. We can go to Xcode-Files-Project/Workspace settings options. You will see that there is a Build System option that allows you to select a new build system. Directly Upload App to AppStore ~ Through Xcode 10, we can directly upload an iOS app to the App Store from the Xcodebuild tool using the following command: ~ “ $ Xcodebuild -exportArchive -archivePath <xcarchivepath> [-exportPath <destinationpath>] -exportOptionsPlist <plistpath> “ ~ We need to pass the ExportOptions.plist file containing the key destination and value upload. Furthermore, we have to ensure that Xcode is configured with the right membership details to be able to connect to the Apple developer portal. Parallel Testing Xcode 10 supports running tests in parallel, which reduces the time for takes to run the test. Test parallelization is supported for macOS, iOS and tvOS unit test in simulators. Version Control Integration Xcode now supports working directly with a few source code collaboration platforms such as GitHub and GitHub Enterprise, Bitbucket Cloud and Bitbucket server and also GitLab.com and Gitlab self –hosted. Asset Catalog Xcode 10 supports the CarPlay assets and ARKit 3D ARReferenceObject asset. It also supports unit varying image and color assets with light, dark and high contrast appearances on macOS 10.14 and above. Code Snippets ~ We can also create snippets for other languages likes Ruby, php, Python, C++, Obj C, etc. ~ We have to define the shortcut keys for the snippets. Closing Note There are new great features included in this version of Xcode that we have discussed in the article above. So you can also go for it and experience the difference. 9series provides you with the best iOS App Development Services where they use the latest tools and technologies like Xcode 10 to develop the most dynamic and user-friendly apps for your business.
Dedicating 6 years in improving & using the Objective-C, Apple finally decided to snap another challenge to developers. Again, iOS developers will have to learn this new programming language - Swift. In this article, we are going to look at some points of Swift compared to Objective-C. If you know Objective-C (at least the basics) then this tutorial is best suited to you and want to see what the equivalents are in Swift. So let’s get into it! Swift Language is Easier than the Objective-C: ~ Objective-C has been created using two languages: C and Smalltalk. hence, Objective-C has such a complex, Verbus Syntax. ~ Objective-C obtains its object syntax from Smalltalk while Syntax for the non-objective operations is similarly as C. ~ While the Swift Language is an option to the Objective-C language, the Swift Language is defined as “Objective-C without the C”. ~ Swift is a comparatively a new programming language. Apple started to work on Swift in 2010 and published it to the public in 2014. In 2015, Swift graced open source. It rejects the Smalltalk and C heritage and has all the features that modern programming languages have: generics, high-ordered functions, type interfaces, Optionals. Swift Support Modern Programming Language Features Swift rejects the Smalltalk and C Heritages and has all the Features that Modern Programming languages have: Generics Generics code allows you to write adaptable, reusable functions and types that can work with any type, subject to requirements that you specify. Optionals Optionals are dominant features in Swift Language which come to resolve the intricacy of non-existing value. Type Interface Type interface refers to the automatic detection of the data type of an expression in a Programming Languages. High-Order Functions High Order Functions is a function that you can pass arguments of other functions. The Following Some High-order functions is: ✓Map ✓Filter ✓Reduce ✓FlatMap ✓Chaining Swift is Faster than the Objective-C ~ iOS development with Swift is much faster than in Objective-C. ~ The Swift usage of generics and higher_order functions results in cleaner, more reusable code. ~ Optionals and type interface resulted in the responsibility for the code safety being transferred from the programmer to the compilation. ~ Let programmers write some lines of code with the similar effect as in Objective-C. ~ This helps to make the development process faster. Swift is Safer ~ Because of its Features - generics, optionals, and type interference - all the apps being developed in Swift are less likely to have bugs or crash than other apps developed in Objective-C. ~ To present an anticipated behaviour Swift triggers a runtime crease if a nil optional variable is used. This crash provides consistent behaviour, which eases the bug-fixing method because it limits the programmers in fixing those issue right away. ~ The Swift runtime crash will halt on the line of code where a nil optional variable is used. ~ This indicates the bug will be fixed sooner or bypassed completely in Swift code. Apple is focused on Swift ~ Apple continually develops these languages and providing continuous support to the Community. In every WWDC there are a bunch of amazing technical talks about Swift; the time indicating that Swift should be taken seriously. Swift is easier to read ~ Objective-C suffers all moles you expect from a language built on C. ~ But in the Swift falls the legacy conversations. Therefore, you no longer need semicolons to end lines or punctuation to encircle conditional expressions inside if/else statements. ~ The Result is Cleaner and a more expressive language with a simplified syntax and grammar. Easy to Maintain Codes ~ Swift code almost follows natural English, in addition to other modern programming languages. ~ And then it also very easy to understand the code and then make the necessary changes simple in Swift. Swift requires less Code ~ Swift decreases the amount of code required for repeated statements and string manipulation. In Objective-C, working with text strings is very tedious and demands many steps to combine two pieces of information. Swift embraces modern programming language features like adding two strings together with a “+” operator, that is missing in Objective-C. ~ The type system in Swift decreases the intricacy of code statements — as the compiler can understand the types. As an example, Objective-C needs programmers to remember special string tokens (%s, %d, %@) and implement a comma-separated list of variables to replace each token. Version History of Swift ✓ Swift 1.1 ✓ Swift 1.2 ✓ Swift 2.0 ✓ Swift 3.0 ✓ Swift 4.0 ✓ Swift 4.1 ✓ Swift 4.2 ~ In a short span of time, Apple has invented many versions of Swift. It has features that are an easier language and provides good features for developing an iOS app. ~ The Apple is regularly updating the Swift Language and making it more easy for us to use each day. Third Party Library ~ In day-to-day many third-party libraries are converting in Swift rather than the Objective-C. Your popularity will increase with your developer’s team ~ According to a 2017 Stack OverFlow Developers Survey, Swift is at the forefront of the most favoured programming language, while the Objective-C is the most dreaded one. ~ Swift syntax is easier to understand for the developer’s team, they can easily understand each other’s codes. Swift Support Dynamic Libraries ~ Powerful libraries had never been supported on iOS until the launch of Swift and iOS 8, despite powerful libraries were supported on Mac for a long time. These dynamic libraries are external to the app are executable but have been included within the app bundle downloaded from the App Store. It decreases the original size of an app as it is loaded into memory since the external code is linked only when used. ~ As a result, the executable is smaller and, because the code is loaded only when it is needed, the startup time is usually faster. Conclusion If you are looking for iOS development with Swift then you can get in touch with us and we will provide you with the best. You can also hire iOS developers from us for your projects. If you any queries you can also write back to us on [email protected].
Every year, Apple announces the new functionalities for the users & developers through WWDC. In 2018, WWDC they introduced iOS 12 with new and enhanced features. Here, we will see what is new in iOS 12. Introduction Apple announced iOS 12 at WWDC 2018 on 4 June 2018. In iOS 12 Apple’s prime focus is on the performance improvement and enhancements in all new and old devices. With this, the device performance will be 70% faster in iOS 12. Now, let’s see all the new features coming to your iOS soon. Screen Time Screen Time will show you every little detail of your apps like how much time you spent on it, when you used it, etc. It also keeps a record of the number times you used your phone and number of notifications you received from the apps on your phone. It will also provide you with a weekly summary of how and when you used the phone and the apps in it. App Limits App limits is a sub-feature of Screen time, it allows you to set a limit on app usage based on the app or its categories. It works for app categories including Games, Social Networking, Entertainment, Education, Reading, Health etc. So you can set a limit of your app. Also, you can sync across your other iOS devices, so you can’t cheat that way. Updated Photos App The Photos app has a new “For You” tab. It shows all the new albums, photos and effect suggestions in case you want to add them to the photos. Also, you can share selected photos or albums with your friends from the Photos app. Siri & ShortCut App ~ It has assigned custom shortcuts to Siri for activating specific actions, which not only works for System apps but also with third-party apps. So now if you want to send a specific message to someone on Chat app (i.e WhatsApp), you can assign a command for that to Siri and you can activate that action just from Siri using that command. ~ Apple adds a new app in iOS 12 called Shortcuts. Shortcuts app lets you group actions and runs those actions quickly. Enhanced Do Not Disturb Do Not Disturb has a new enhanced feature "Bedtime mode". Enabling it will enclose all your notifications at bedtime and will dim the display. When you wake up, it will greet you with a welcome back message and show you the weather details on the lock screen. Notification Notifications can now be grouped. Hence, all your notifications from the same app are grouped together allowing you to control how often you want to get notifications from the apps. Messages ~ The Messages app gets new Emoji characters and Memoji are like personalized emoji. They look more like three-dimensional than the custom Bitmoji you make in other apps like Snapchat. ~ Users can customize their Memoji with hundreds of options for skin color, hairstyle, facial features, and accessories like hats and glasses. You can save multiple Memoji and use them in Messages to send reactions to your friends. ~ The Message app gets new filters for sending photo and video responses, and you can add stickers. Measure ~ Apple is bringing ARKit functionality to their app without any third party in iOS 12 called “Measure”. ~ You can now send AR objects through Messages and Mail, which can be viewed in the real world. You can measure the object in real-world by pointing your camera on the specific object. Conclusion ~ The Apple iOS 12 comes with a new and has enhanced its features too. This is currently available in the beta version. ~ The app developers can leverage with the new features by adding more creativity and experimenting with these features. ~ iPhone/iPad users will get more personalization, improved connectivity and enhanced security with these features. Above are few points on iOS 12. Though we have tried to cover the important points, yet, feel free to post any missing points or share your thoughts about these new features in iOS app development. Want to share something innovative about the new release? Feel free to write to us at [email protected].
1. Introduction: MVVM is an abbreviation of Model View ViewModel. A Model-View-ViewModel is software architectural pattern that was created way back in 2005 by John Gossman. MVVM is quite similar to MVC, but it provides better connect of the UI and business sense than that of MVC. In MVVM pattern, each view on the screen will be backed by a view model and it represents the data for the view. 2. MVVM flow Layout & Theoretical Background: In an MVC-based project, View is Connecting with its ViewController. ViewController is easily overloaded and increases its size when the application becomes bigger. So ViewController is affected in MVC. This drawback Solution in MVVM pattern. MVVM Data flow shown in Below Fig 1. As per above figure, the three core components of MVVM model respectively are, 1. As per above figure, the three core components of MVVM model respectively are, 2. Model: it is class that holds our App Data. 3. View/ViewController: it presents our View and ViewController Class. 4. ViewModel: ViewModel binds the Model and ViewController, it’s the heart of MVVM design pattern. It provides the connection between the model class and the view/view controller. View Model is capable of observing changes in Model and synchronize itself with the events. Example: Let’s start Understanding MVVM Design pattern with a simple example. First, create a project in Xcode. Also, create Model and ViewModel Class. In this project, we have taken tableView and shown employee name and its department using MVVM design pattern. Model: Shown model class in below Fig 2. In model class, we have defined variable and function, as per our requirement. Fig. 2 View-Model: - In View-Model Class we have taken a Model object, so we have used - Model class property in View- Model Class. In our project model Employee is a model object. - Here Model and View-Model class are connecting to each other. - Shown View-Model Class in Fig. 3 Fig. 3 View (Controller): - First, take View-Model object in ViewController Class. myViewModel is View-Model object. In our project, we have taken table view. - In this class, View-Model and View-Controller are connecting to each other. View-model object through, we get all data of View-Model class as per requirement. - View (Controller) class shown in Fig. 4. Fig. 4 Also shown Output in fig. 5 Fig. 5 Advantages: - Code reuse: In View-Model class we implement init, setup and view presentation method, so we use this functionality in each new view controller. - Improved Testability: In MVVM we can make all classes separate so we can easily find an error. - Reduce code size Disadvantages: - MVVM pattern not useful for single View application, when we work on Multiple views then it is useful. Conclusion: MVC and MVVM both patterns are useful for iOS app development. MVVM is new Concept for the design pattern. MVVM is more useful when app size is bigger because the separation of Model, View and View-Model class can reduce complexity.
As we all know that Apple has introduced an API for natural language processing from iOS 5, which allows us to tokenize text, detect the language and determine parts of speech.
Basically Natural Language Processing (NLP) is used to either predict your next word or suggest a correction while typing a word. NLP is likely used in Siri.
The main API is NSLinguisticTagger which is used in analyzing and tagging text, segmenting content into paragraphs, sentences, and words. In iOS 11, NSLinguisticTagger becomes more powerful. It is used for following schemes,
Let’s take experiment with the new NLP API. At first, we need to do is create a tagger. In NLP, a tagger can read the text and give different information to it such as part of speech, recognize names and languages, perform lemmatization etc.
When you initialize NSLinguisticTagger, you have to pass in the tagSchemes in which you want to perform. Let’s do it:
1. Language Identification
You can retrieve this language by accessing the dominantLanguage property of the NSLinguisticTagger. NSLinguisticTagger analyzes the text to get the dominant language.
The punctuations and whitespaces are omitted with NSLinguisticTagger Options. Tokenization is the process of classifying the text into paragraphs, sentences, and words. We call them tagger.enumerateTags function to tokenize.
It will be splitting the above string into words and then we get the list of each word that is there in the sentence.
Deriving the dictionary form of the word is called Lemmatization. For example, a user wants the result for word ‘run’. if you were able to consider base forms of the word, you would be able to also get results for ‘running’, ‘ran’, ‘will run’, etc.
Here the raw value of the tag is lemma of a particular word. So In output we got is stem form of each word token.
4. Parts of Speech
This is used to get each token’s lexical class. It will return each word and its part of speech. You can see the noun, preposition, verb, adjective, or determiner.
In the output, You can see the verbs, nouns, prepositions, adjectives, etc.
5. Named Entity Recognition
Named Entity Recognition is allowing you to recognize any names, organizations, or places. You would have seen certain keywords highlighted like numbers, names when you use some iPhone application.
In the following example we identify whether the token is named entity like personal name and place name.
Here we have used tag variable which is used by tagger to look for particular tags in sentence.
Natural Language Processing is already a powerful tool, growing exponentially and that can be widely used in the Applications. Apple’s Siri and Facebook’s messenger bots are the best examples of NLP.
In this article, we, 9series, have covered about NLP, its terms and how it works. If you have more experience with it or find more features then feel free to share your own experience with us.
Stay tuned for upcoming articles.
As we all know following a procedure can be very boring, hectic and time-consuming in the development process. Most of the developers working in an iPhone app development company in India have the tendency to jump directly into the coding because of all the effects and fun there.
According to our experience in application development, it is very helpful to follow some practices before jumping into the coding part. It always helps in reducing complexity, increasing the readability, easier to maintain, avoiding redundancy, etc. Also, it is helpful to other team members to understand the concept and the flow of the application if working in a team.
So, let us check and dig the topics one-by-one which will be helpful to create a proper architecture of the application and also be helpful for the entire team in the future.
1. Define Coding Style
Coding Style is the most important aspect that should be defined before you start writing any application, especially while working in a team.
It includes the below points:
2. Define Architecture for The Application
It is necessary to decide the architecture for the app before diving into the code. Choice of suitable architecture will make the app more testable, easier to understand and reduce its maintenance cost. You can choose any architecture from traditional MVC to recent or fancier MVVM. There are so many resources available on the web from which you can understand and decide architecture for the application. Below is some reference for the design pattern. https://www.raywenderlich.com/132662/mvc-in-ios-a-modern-approach
3. Setup Folder Structure
Instead of keeping all the files in a single directory, it is a good idea to follow some folder structure for the project. It will make the files well organized and easily findable, you can use the following:
Although this may look negligible at the first sight but for the big projects, it is certainly more helpful, well structured and easier to understand for every team member working in the project.
4. Manage Your Dependencies
It is very certain that everyone is using some third party libraries in their application. So for that, you should use one of the dependency managers from the ones that are already available. We usually prefer CocoaPods which has the vast collection of libraries and easy integration facilities, you can use any of below depending on the requirements.
5. Setup Certificates and Profiles for Code Signing
Most annoying and painful task of the application development is creating certificates and provisioning profile. This process includes creating application id (Unique identifier for the device), adding devices to developer account, creating certificates (development certificate for debug the application and distribution certificate for releasing the application.), creating provisioning profiles (same as certificates), also creating APNS certificates if your application is willing to get the push notifications from the server, providing .pem file to PHP developers or .p12 file to .NET developers.
6. Continuous Integration
This is very much advisable either working in a team or individual. This will keep track of your development process and at any point of time, you can check the updates for the particular date or time period. You can use either git or SVN whichever is suitable for you for the continuous integration. This will help all the team members to pull the latest updates done by the other member as well as push the new changes to the other team members. The main benefit of this is you will have all your code on the server and you will be able to access it from anywhere.
7. Setting Application Icon and Splash Screen
Though this is not a mandatory task and not that much important for the initial stage but setting it initially make your application first impression good. Application icon carries a variety of sizes of the single image so instead of forcing designer for all size images you can just ask of 1024*1024 size icon with some background and you will be able to get all the required size images from some online or online tools. Splash screen set up is also carry 2 ways either you set the launch images or you can use the launch screen for setting up the splash screen.
In this article, we have covered the major points about defining the iOS Application development Architecture. Though list can be expanded more with more topics like how code style should be applied, commenting guide, etc. You can also add your own topics, thoughts, etc. and feel free to share with us.
We hope that these tips will be helpful for you to define and start the application with the best style.
Happy Coding! and feel free to share your own experience on “[email protected]”.
Hello everyone, as we all know that Share Extension is appeared from iOS 8, then the capability to share content with other entities, such as social sharing websites or upload services can be done in an easy and convenient way.
We, 9series, an iOS application development company has started doing all the development using Advanced Programming Language Swift.
So today, we are going to build a Shared Extension app in iOS10 with Swift 3.0, an ability to show an icon on the common share-sheet that associates with our main app, which handles the sharing of the content that the user has requested. So the user can easily switch from one app to another, for example, we are sharing a photo from the album with some content that switches our app where we want to upload data to the server.
This is mainly a programming article, so you are required to have Xcode 8 on Mac. Let’s get started !!!
1. Make a new Xcode Project
First Create a cocoa touch Single View Application in Xcode 8 with some basic UI. Like it is shown below
Design the screen with UILabel, UIImageView, UITextView and with UIButton. When user comes with some sharable content from parent app, we can upload or we can use anywhere in our app.
For Eg, let’s create the Share Extension.
Give some proper name of that extension and it will show you popup view for activating your extension scheme. Choose Activate to use this scheme for building and debugging.
Note: Schemes can be chosen from the toolbar or Product menu.
3. Make an App Group
We want to communicate two app for sharing some content, but Apple doesn't want a complete free flow of data between the two. Apple recommends a shared NSUserDefaults as a meeting ground where the two app can exchange their data.
Now, we need to make an app group.
Click on your project in the Navigator Pane of Xcode, click on capabilities and your app under the target list turns on App Groups. Give it a name like “group.BUNDLE IDENTIFIER”.
Now click on your extension and do the same.
4. Implementing Share Extensions in Swift
First open your viewController, we won’t go into much detail, because it's a destination viewController. So we can read content data from User Defaults which is shared by user from Share ViewController.
We have also created an IBAction of Upload button, so that content and photo which is shared by user can be used anywhere in our app.
Here, “sharedIdentifier” is the UserDefaults suiteName that we have used for the app group name. An extensionContext where we get a list of NSExtensionItems. This is a fixed array of data sent to our extension from a parent app. We are getting photo and content from our photos app that are already set to our main app.
Let's look at the “ShareViewController” from our Shared Extension Folder which is subclass of SLComposeServiceViewController. SLComposeServiceViewController has some methods and properties associated with the lifecycle of a share-sheet composition view.
isContentValid() :- It is called every time when the content in the compose view changes. Here, we can check the input data is valid or not. It is called first, and will disable the post button when it evaluates to false.
didSelectPost() :- As the name suggests, it is called when the user presses the post button. Here we can do something with the user input. Once the upload is scheduled, you must call completeRequestReturningItems(, completionHandler:) so that the host app can un-block its UI. When the upload request is done, it calls the completion handler that was passed into the previous mentioned function call.
configurationItems() :- Here, we can add more things for the user to select when they are sharing. In our case we are sharing a photo with contentText. You can also make it more dynamic with some other controls.
contentText :- A string which represents what the user has typed into the composer.
charactersRemaining :- Is a number which appears on the compose sheet. When negative number shows, its appearance becomes red.
Here is the code of “ShareViewController”
Here, we are selecting one image from photo album and then clicking on share button, it will open share sheet with our Share Extension app Icon.
Select that app and it will open composition view.
We have mentioned maximum characters of contentText as 100, so if you enter more than 100 characters, than it will generate alert message and post button will be disabled. You can also check number of characters at the end of compose sheet.
Configuration! items is where we can add more things for the user selection, when they are sharing. Like, Open UITableViewController as subview Controller and selecting User Input it will display as item value at the bottom of compose sheet.
Configuration! items has title, value, and a tapHandler. So you can add extra functionality for selection from User.
ExtensionContext has list of attachment as NSExtensionItem. We’ll loop through the attachments, and look for one typed as an image. It will have the type identifier kUTTypeImage. NSItemProvider items are lazily loaded images, videos, URLs and so on. We’ll load it using “loadItemForTypeIdentifier”. This has a completion handler, where we’ll read the image from the URL, and then we’ll save it to defaults.
After pressing Post Button, It will save Image in UserDefaults with “Image” key, and contentText with “Name” key.
We have created two utility methods for saving data to user defaults and for alert message.
Till now, Apple wouldn’t accept this in their app store. We need to tell iOS when to show our share extension, and what can be selected. Otherwise when we compile we’ll get a warning.
“Warning: Embedded binary’s NSExtensionActivationRule is TRUE PREDICATE”
So for that, open the “info.plist” as source code by right clicking on it. We’re going to change the NSExtensionAttributes section. This means our extension is activated only for images, and only when it’s a single image. If you select more than one image, the extension app automatically hides from share-sheet.
You can change your display name of your app in share sheet by replacing the code in the “info.plist” of your Extension.
5. Test Your Share Extension
1. First you have to simply run your app.
2. Then run your Share Extension.
3. When suggested to choose an app to run, choose Photos.
4. Once the extension starts running, select a photo and tap on the Share button.
5. On the first run, you will need to add your extension to the share sheet.
6. Click on the More button to the right of the other share icons and turn on the switch for your extension & then select Done.
7. Now you will be able to see your extension icon in share - sheet.
8. Select an individual photo and click on share. By selecting your app, add some content and press post button.
The image will be saved to your main app. To confirm this, redirect to your app. You can check the content you entered in the textview and the image above the content.
In this article, our best iOS application developers in India, have only covered some basic UI. You can also make it more dynamic with other controls.
Hopefully, all of this will help you share data with your parent app.
Happy Coding! and feel free to share your own experience on “[email protected]”.
Hey, welcome back!!! Let’s move one step ahead with the open source development language from Swift 3 to Swift 4. We, at 9series, have filtered out points of our next strides in developing mobile apps using Swift 4.
Swift 4 is the latest major release for iOS App Developer that is intended to be completed in the fall of 2017. Its main focus is to provide source compatibility with Swift 3 code while implementing essential feature work that needs to achieve binary stability in the language. It will contain valuable enhancements to the core language and Standard Library, particularly in the generics system and an overhaul of the String type.
Source Compatibility Modes
The Swift 4 compiler will provide two language modes: Swift version 3 and Swift version 4. Swift 3 established the language for source-level stability and now Swift 4 releases source compatibility as a feature moving ahead.
New Features in Swift 4
Swift has many other features to make your code more expressive:
Multi-Line String Literals
To start a string literal, you need to write three double quotation marks: """ then press return. After pressing return key, start writing strings with any variables, line breaks and double quotes. To end multi line string literal again write ””” in new line. Ex:-
Strings are Collections
Just like in earlier version of Swift, Strings can be handled as a collection. No need to write string.characters.something to perform string manipulation.
Dictionary Functionality has Improved
Swift 4 combines some additional functionality to dictionaries to make them more strong, and also to make them work more like you would expect. Let's start with a simple example: Modifying dictionaries in Swift 3 does not return a new dictionary. Instead, it returns an array of tuples with key/value labels.
After that code runs you can't read distinction["Maths"] because it is no longer a dictionary. Instead, you need to use distinction.value, which is not good for us because we apply filter on dictionary and we got an array.
As of Swift 4, this acts more like you would expect: you get back a latest dictionary. Obviously this will break any existing code that relies on the array return type.
Similarly, the map() method on dictionaries got a key-value tuple passed in, and could return a single value to be added to an array.
That has not changed in Swift 4, but there is a new method called mapValues(). It allows you to modify the values and place them back into a dictionary using the original keys.
Here we try to form different buckets where each bucket will contain values having same first character in their name. For Example:-.
It's now likely to obtain a dictionary key and provide a default value to use if the key is missing. In following statement if there is no value for key “Bio” found then it will print default value.
Built in Encoding and Decoding
Swift 4 appears with built-in encoders and decoders for JSON. JSON to Model conversion comes in built in.
One Sided Range
Swift 4 introduces Python-like one-sided collection slicing, where the missing side is automatically assumed to be the start or end of the collection.
Like with other Swift releases, 4.0 was announced at WWDC '17 and released in beta form for developers alongside Xcode 9. This release of Swift added quite a few refinements and features to the programming language. First release of Swift 4.0 will bring overall stability to the source and binary interface, or ABI.
Stay tuned for other technical and development articles.
Eagerly waiting for the features of Xcode 9? Here it is. Apple has released Xcode 9, the newest version of its free integrated development environment (IDE) for building iOS application, macOS, watchOS, and tvOS apps.
With everything you need to create amazing apps for Apple platforms, Xcode 9 is unbelievably quick and consistently smooth while editing even the largest files. It also understands your code better than ever. Powerful new refactoring tasks happen in place, renaming symbols across Swift, Objective-C, and even user interface files without skipping a beat. And with source compatibility in Swift 4, Xcode 9 uses the same compiler to build existing Swift 3 code and updated Swift 4 code, so you can migrate at your own pace.
Brief About Xcode 9
All New Editor
Xcode 9 has a brand new Source Editor, entirely written in Swift. In the new editor you can use the Fix interface to fix multiple issues at once. Also, when mousing around your projects, you can hold the Command key and visually see how structures in your code are organized.
The source code editor has been completely rebuilt for amazing speed. It scrolls at a constantly smooth rate, no matter the files size. And it looks better, too, with preferences that give you greater control over line spacing, multiple font styles, and even the type of cursor. Issues have been redesigned to flow nicely with your code with Fix-its that are grouped together so you can commit multiple changes in a single click.
You can now increase and decrease the source editor font using ⌘ with + and ⌘ with -. When text is selected, typing an opening delimiter adds a matching closing delimiter at the end of the selection.
Refactor and Transform
The new editor goes beyond text entry with a new built-in refactoring and transformation engine. When you select a symbol or block of code, the editor will offer powerful operations such as ‘Extract’ or ‘Rename.’
One of the most basic refactorings is to rename a class, and all references to that class in the project are renamed as well, including references in the Storyboard and the filename itself.
Xcode 9 supports the following transformations and refactorings:
Groups in the Project Navigator are now more closely associated with directories in the file system.
Source Control and GitHub
Xcode 9 now connects easily with your GitHub account making it very easy to see a list of your existing projects, clone projects, manage branches, use tags, and work with remotes.
With your GitHub account built into Xcode, the clone window shows all of your personal GitHub repositories, as well as all the repositories where you added a star. From this window, you can search all of GitHub and check out a project with just a click.
A new indexing engine runs as part of the build process, so Xcode understands your code automatically.
Searching large projects feels quick – up to 50 times faster. And a new build system dramatically lowers the overhead of tasks that coordinates compiler, linker, and other tools.
With Xcode 9 and Xcode Server, we have almost everything in single place used to create apps for Apple TV, Apple Watch, iPad, iPhone, and Mac. As we know and experienced that no softwares can be complete or can be in a finished version, there are many new great features included in this version of Xcode. So we should definitely go for it and experience it.
We, as a mobile app developer believe that using Xcode 9, development can be done faster and can be pushed ahead with the next strides.
In this article, we, 9series, have covered about what is new in Xcode 9. If you find any new features or might have experienced with existing one then feel free to share your own experience with us.