Tag Archives: Xcode

How to add a macOS target to your iOS App

To write cross-platform applications, it can be beneficial to have a single project with several target architectures. For example, we may want a macOS App inside a project that started out as iOS, and vice versa. Or we may want a different version of our app, perhaps a free one with less features, and an expensive one with more, based on the same code.

That’s where Xcode Targets come in. A Target is something that defines several build settings about an app so that when we press that popular button in Xcode, it knows what to do so we can see the built app in full colour. Trust me, there’s a lot going on under the hood – if you’ve ever tried to compile from the command line, you know how super helpful that button is. But I digress…

In this example I’ll show you how we can add a macOS Target to an iOS App’s Project. This will allow us to run and build either an iOS or a macOS version from common code.

Let’s begin. I’m using Xcode 8.3.3 for this by the way.

Adding the Target

In a standard Xcode Project for iOS, we already have a single target. Click on the blue project bar and select it from the list next to the File Inspector. It’s the one with the yellow icon:

Continue reading





How to submit your apps to the App Store with Xcode 8

In case it’s been a while that you had to deal with App Store submissions, here’s a quick refresher. This assumes that iTunes Connect is ready to receive a new app or update.

Make sure that the version number and build values have both been increased if your submission is an update. In Xcode, do the following:

  • verify that the Archive Scheme is set to Release (under Product – Scheme – Edit Scheme)
  • make sure that you’ve selected “Generic iOS Device” as the active scheme
  • head over to Product – Archive to create an archive of your current version
  • the Organizer window opens, showing previously archived versions of your app (don’t delete those)
  • now hit Validate to see if there are any issues with your app
  • if all is well, hit the big blue Upload to App Store button
  • now pray that your app is approved





How to fix http load errors in Xcode

In 2016, Apple have implemented a new rule that won’t let us load data from unsecured websites anymore. That’s those beginning with http:// instead of https:// (the latter ones are secured with an SSL certificate, and hence traffic is encrypted).

When you load an unsecured source, you’ll get an error message like this:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

If a secured source of the data is available, it’s probably the easiest method to change the feed. However, if that’s not an option, we can convince Xcode to let our apps download what’s known as data from “arbitrary” sources. Here’s how to do it.

First, in Xcode, navigate to your project’s target and find the Info tab. The target is the one that has your app icon showing, NOT the blue Xcode icon (top left, in the Project Navigator).

Now right-click on any of the many lines and select “Add Row”. This adds a value to your Info.plist file. Notice a list that comes up. Either select “App Transport Security” (if you can find it), or type NSAppTransportSecurity (it usually auto-completes). The entry will change into App Transport Security.

Let’s add the appropriate values to this new entry now. Hover over your new row now and select the little plus icon that comes up, then choose “Allow Arbitrary Loads” from the list. Alternatively, type in NSALlowsArbitraryLoads. Again this value will change to Allow Arbitrary Loads. Notice that this entry is a BOOL, and it needs to be set to YES on the right hand side. Go ahead and do that.

This will be enough to allow HTTP loads inside your app from any URL. You can restrict this to only certain URLs or hosts by adding another entry to the App Transport Security line, namely “Exception Domains”. Add each domain to its own line, and only data from those will be allowed to load via HTTP. If you want to use restricted domains, make sure to set the Allow Arbitrary Loads value to NO.





How to avoid “Capturing ‘self’ strongly in this block is likely to lead to a retain cycle”

I was trying to update a UILabel from inside a block the other day, and was puzzled by the above Xcode warning: “Capturing ‘self’ strongly in this block is likely to lead to a retain cycle”. The full code looked like this:

 

self.mainController.controllerPausedHandler = ^(GCController *controller){

        // triggers a warning
        [self displayMessage:@"Pause Button"];

    };

As it turns out, the trouble was that a block executed in self cannot capture a reference to itself (self) without there being a never ending loop involved. It’s probably to complicated for me to understand and/or care about, but thankfully there’s a relatively easy way to correct this problem.

Continue reading





How to fix “no rule to process file” warning in Xcode

The other day Xcode was trying to tell me that it had “no rule to process a file”. It was a simple readme file that I had created on GitHub and subsequently pulled into my working copy.

Even though the project compiled fine, if there is a warning we can eliminate, we definitely should. Turns out it’s easy fix this problem.

Click on your project in the Project Navigator (the blue item on the left where you see all your project files), then head over to Build Phases. You’ll find a section called Compiled Sources. Expand it to see a selection of files.

Select the one Xcode is complaining about and remove it by clicking the little minus sign at the bottom.

Screen Shot 2015-12-09 at 12.51.27

Build the project again and see that warning disappear for good.





How to build WordPress for iOS (2015)

WordPress-LogoThe WordPress for iOS project has changed and grown over the years. While it’s still Open Source, it’s not as easy as “checkout and deploy” anymore. You may encounter several pitfalls along the way.

At the time of writing, the current version of WordPress for iOS is 5.7, with 5.8 just around the corner. In this article I’ll show you how to build the project and deploy it on your own devices.

Continue reading