Lastly, we are going to add a navigation bar for showing the title of the app, and a toolbar at the bottom side of the screen where we will add a bar button item. For keeping a visual consistency, we will also apply the color of the navigation bar to the status bar.
Beyond all that, we are going to create an auxiliary class, which will be used to store various data regarding a file and its download status. Actually, an object of that class will match to a file, so we are going to have five objects in total stored into an array. More about all these later. As a final note, for testing the background download of the files meaning when the app is not running , we are going to send a local notification to inform us when they are all finished.
Before we do the first step, please download the icons that will be used to the app from here. Launch Xcode and create a new project. In the guide window that will appear, make sure to select a Single View Application , in the Application category under the iOS section. Click on the Next button to proceed. Once you are ready, click one again on the Next button to go to the last step of the guide. In this window, just select a place to save your project and click Create. You are ready to go!
We are going to begin the development of our app by setting up and configuring the interface using the Interface Builder. Click on the Main. For starters, grab from the Object Library a Navigation Bar , add it to the view and set its following attributes:.
Next, get a UIToolbar and place it to the bottom of the screen. Select the existing bar button item, and set its Identifier to Refresh. Here it is:. Set its frame to 0, 64, , After that, get a UITableViewCell object and place it on the table view that you added previously to the view. Select it and set the next couple of attributes:. In the cell prototype, we are going to add some subviews. Begin with a UILabel , by setting the next properties of it:.
Get another UILabel from the Object Library, add it to the prototype cell, and set its next properties:. Now that all the subviews have been added to the main view, we must declare an IBOutlet property for the table view, and some IBAction methods that should be connected to the appropriate controls.
Begin by opening the ViewController. In there, add the next code segment:. Return to the Interface Builder and connect the tblFiles property to the table view. Next, match the action methods with the subviews as shown below:. The interface is now set up and configured, and that means that we can move forward to the implementation of the app.
Now that the interface of our app is ready, we can proceed in coding. However, before we perform any implementation, we are going in this part to create an auxiliary class that will help us keep vital data throughout the project. On your keyboard hit the Command-N combination to let Xcode present the guide for adding a new file. Then, in the Class field set the FileDownloadInfo as the class name.
In this class we are going to declare a bunch of public properties, and a custom init method. Note that a download task provides ways for checking the download status of a file.
However, we declared our own properties here so we can work more in convenient way. In this one, we will provide the file title and the download source as parameters. Here is the declaration:. Our class is ready. As a final step, go to the ViewController. Before we dive deep in writing code, we must do a necessary configuration, so our app be able to use the Background Transfer Service.
In the Project Navigator , select the project target at the top side. Next, in the main window click on the Capabilities tab, and all the features that you can enable or disable simply using a switch button will be displayed there. Among them, locate the Background Modes area second from the end , and click on the switch button at its right to enable it.
In this part of the tutorial we are going to perform two tasks: The first one is to declare some private properties in the ViewController class, as well as some constants, and the second is to initialize five FileDownloadInfo objects that will be used for handling all the download process. These constants match to the tag values we set to the subviews of the prototype cell in the Interface Builder.
We will perform this step even though is optional, so instead of having to remember the tag value of each subview, we will just use the constant name when we want to make a reference to any of them. In the ViewController. Add the next lines:. We will work with that in the next section. The arrFileDownloadData mutable array, is the array in which they will be stored the five FileDownloadInfo objects that we will create in a while, where each such object matches to a file.
In the code fragment that follows, the array is firstly initialized and then they are added to it five FileDownloadInfo objects. These objects are initialized and added to the array at the same time. Note that we use the custom init method we created to the FileDownloadInfo class, so we provide as parameters both the file title and the download source for each one.
Now that this method has been defined, it must be called every time the app is launched. Therefore, go to the viewDidLoad method and make that call:. So far, so good! Add the next couple of lines to the viewDidLoad method:. Lastly, add the next few lines that make self the delegate and datasource of the table view, and disable the scrolling on it:.
Up to this point, we created the custom class that we will use in our project, we declared some private properties and we did some initializations.
First of all, open the ViewController. Before I present it, let me say in short what is going to take place in it. At this point, you may test the app for first time.
Previously, we declared a private property named session , which is an object of the NSURLSession class, and now we are going to work with it. In order to create a session for initiating download or upload tasks either on the background or the foreground, another class must be used, and that is the NSURLSessionConfiguration class. Through this, various session properties and policies can be set, a list of which you can find here.
What we are going to do here is pretty straightforward: At first, we will instantiate a NSURLSessionConfiguration object using the backgroundSessionConfiguration class method, we will set a desired property value, and then we will instantiate the session property. However, there are two more class methods for instantiating a session configuration object: The defaultSessionConfiguration which causes the session to behave just like the NSURLConnection with a default configuration, and the ephemeralSessionConfiguration which is useful when no persistent data storage of cookies or credentials is required.
The backgroundSessionConfiguration class method accepts one parameter, an identifier , which uniquely identifies the session started by our app in the system. Through this, we will allow five simultaneous downloads to take place at once.
In code, go to the viewDidLoad method and add the next lines:. You see that as the identifier value for our configuration object we set the com. When using this init approach, you can now initialize each ad unit separately at different touchpoints in your app flow in one session.
To verify your ironSource SDK integration as well as any additional ad networks you have implemented, simply add this method to your project:. For more details on the ironSource Integration Verification tool navigate to this article.
You just integrated the ironSource SDK in your app. You are now ready to start working with the ironSource Ad Units and advanced mediation platform. See Xcode Help. Open the Terminal app on your Mac.
Enter the following command at the Terminal prompt:. If the name contains spaces or special characters, enclose the name in quotation marks. Do not modify the following: app. In Xcode, click the disclosure triangle next to your project in the project navigator. Click the disclosure triangle next to the Custom Application Resources folder. Update the following information: launchSolution: Specify the custom app file to open when your app is launched. The filename is case sensitive.
If no URL is specified, the Help menu is removed from the app. Update the value for solutionCopyOption to specify when to copy the files in the Solution Files folder to the Documents directory on the iOS device. You can specify either the number or the string. App icons Create different sizes of the app icon for each app to make sure it displays correctly on all supported devices. The recommended file format for icons is PNG.
Click AppIcon , then drag each image to its target box. Click LaunchImage to add your launch images, and click ObscureIcon to add your security shield images. Drag each image to its target. If you do not provide all versions, delete the remaining placeholder files. Click Info. In Xcode, select your project in the project navigator. Click Capabilities at the top of the project editor. Enable iCloud , then select iCloud Documents to allow transferring data to and from iCloud.
In the Identity section of the General pane, specify the version and build number for your app. Note: You cannot specify more than one URL scheme. Click Info at the top of the project editor. Specify information for the identifier, URL scheme, and role. Make sure your Mac is connected to your iOS device. In the workspace toolbar at the top of the window, click the name of your app, then choose the target device to use for building and running your app.
0コメント