Mobile SDK Install - Detailed help for Cocoapods install

While trying to follow the Mobile SDK install instructions I hit a sticking point, so here is a short tutorial with more detailed steps and information than are to be found in the Particle Docs as of 5/22/15.

First, download the SDK from the link on the Mobile SDK page. Put the folder in Documents, or wherever you keep example code.

Create a Swift project however you wish, or to just get started, File -> New -> New Project -> IOS -> Application -> Single View. Store it wherever you like. Desktop might be a good place as youā€™ll be opening the folder in a minute.

After you create the project, quit Xcode. Open the project folder on your desktop so you can keep it in view, and then launch Terminal.

From Terminal, do thisā€¦

1 Update Ruby by typing: sudo gem update --system
2 Install cocoapods by typing: sudo gem install cocoapods
3 Navigate terminal to the project directory by typing: cd yourDirectoryName
4 Confirm you are there by typing: pwd
5 Create the podfile by typing: pod init
6 Edit the file by typing: open -a Xcode Podfile
7 Replace all text with this line: pod ā€˜Spark-SDKā€™ then save this file and quit Xcode.
8 In Terminal type: pod install

You should see some confirmation messages. Pay attention to this one.
[!] Please close any current Xcode sessions and use yourProjectName.xcworkspace for this project from now on.

To clarify that message a bit, it means, Do not open your project from the Xcode menu targeting the Project folder, or by clicking on the .xcodeproj file in the project folder. To be save, launch the project by double clicking the .xcworkspace file in the project folder.

You will need to repeat steps 3 - 8 for each project you want to use the Mobile SDK in.

DO NOT USE TextEdit TO EDIT THE PODFILE. If you simply click on the Podfile to launch an editor, you will launch TextEdit and the quotes TextEdit uses are not compatible with pod install. It wonā€™t complete the install and you will get an error message like this one.

[!] Invalid Podfile file: undefined local variable or method `ā€˜Sparkā€™ for #Pod::Podfile:0x007fd68411bea0. Updating CocoaPods might fix the issue.

This message has nothing to do with updating cocoapods and that wonā€™t resolve the problem. Like a missing semicolon five lines away breaking some other line, those bad quotes cause some sort of cocoapods error and you wonā€™t be able to run pod install.

After a successful installation of pod install, your project directory will look like this:

Here is a very detailed post on cocoapods http://www.raywenderlich.com/64546/introduction-to-cocoapods-2

I hope that saves some of you the days it took me to find out why the Podfile would not install. Iā€™ll be creating mobile apps in Swift, so according to cocoapods there are more steps required to use cocoapods in Swift. Ive posted another short tutorial on how to create and install the Bridging Header file required to use the Spark SDK from Swift.

There is no need to read further. This entry had been updated with all the useful information.

Indeed you should install Cocoapods before starting with Particle iOS Cloud SDK.
This is done easily by running:

sudo gem install cocoapods

on your command shell. For additional help installing cocoapods refer to this page.
once cocoapods is installed on your system just create a file name Podfile at the root of your XCode project, file should contain one line:

pod "Spark-SDK"

then run the command pod install on that folder and the iOS cloud SDK will install into your XCode project.
Also run this command before experimenting with the example app provided.

It all sounds so simple when you say; ā€œFor additional help installing cocoa pods refer to this pageā€. Alas, if only ā€œthis pageā€ did have additional help that I could understand. Since it does not, and since I spent a lot of time reading it and trying to understand the references to Ruby and version anomalies, it deterred rather than helped me.

Since Iā€™m new at pods, could you tell me if I did the installation correctly? I opened Terminal and typed in sudo gem install cocoapods. That generated a warning and asked for my password. I provided it. After some half minute of delay, messages appeared, parsing, installingā€¦ Finally, 19 gems installed.

Is 19 gems installed the correct completion of that step?

Then I created a new blank Swift file named Podfile at the root of my new, empty Swift project. I put in the line; pod ā€œSpark-SDKā€. That generated a compiler error; Consecutive statements on a line must be separated by ;

Your last instruction, "run the command pod install on that folder has me stumped. There is nothing in a drop down menu labeled pod install.

The closest I could find was under Product, Perform Action, Compile Podfile.

I tried that and it generated an error, Expressions not allowed at the top level.

So Iā€™m stumped on the last step. How do i perform the ā€œpod install on that folderā€

And finally, given that youā€™ll explain how to perform the above, when you write ā€œAlso run this command before experimenting with the example app providedā€, you mean, create the empty file at the root, add the line, and run the install. All three steps, yes?

But if thatā€™s not what you mean and the example has the Podfile in it, does you instruction mean that every time I open a Swift project with the Podfile in it, I must ā€œpod installā€ before attempting a compile?

Thanks for your help.

Regarding the cocoapods installation - sounds you did it right.

Now, the mistake is you should create a file called Podfile, no extension. It is not a .swift file, itā€™s just a plain text file.
Do not try to compile it (it wonā€™t), and do not add it to your target (uncheck ā€œtarget membershipā€ for this file).This is purely a directive file for cocoapods, not for XCode.
you can create this file with any text editor, not necessarily XCode. file should be placed in root folder of the XCode project. Only then run the pod install command from shell, this will embed the iOS Cloud SDK into your blank project. If it is a swift project you WILL need to complete several other steps as described in the Swiftalicio.us website.

I can recommend you leave Swift and start from Objective-C project to start learning as it is simpler to understand and integrate with external APIs. Objective-C is still supported and will be so for the foreseeable future by Apple. Most external libraries for iOS are still in Objective-C.

1 Like

Removed the swift file. Created a Podfile.txt file with this text from the Swiftslicio.us instructions

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
 
target "Spark_SDK_First_Try" do
    pod "JGProgressHUD"
end

Itā€™s simply named Podfile and not Podfile.txt :slight_smile:

Removed the .txt extension and got exactly the same error.

It looks like you are not in the directory thoughā€¦Try to cd into the directory storing all these files

OK did cd to the directory and got No ā€˜Podfileā€™ found in the project directory.

See screen shot above. Is it in the wrong place?

  • cd Desktop
  • pod install

It might be better for you to place everything in a folder in the desktop and cd into the folder.

If you want to check the current path, you can type pwd to check that you are at the right place :smile:

current path shows at the Spark_SDK_First_Try folder, which is a separate folder on the desktop. See screenshot above of Finder window
And thank you for helping me :smile:

Can you do the following:

  • place all the files into a folder called app-example
  • type cd
  • type cd Desktop/app-example
  • type pod install`

@ido is the best person to check that the files are at the right place :smiley:

See the directory and Terminal responsesā€¦ Terminal is blocking view of .xcodeproj file. It is in the directory with Podfile.

Hi @ido,

Thanks for the additional help. Kenneth moved me a bit closer, but I am still getting an error that is holding the install up.

I appreciate your advice to move to Objective C, but Iā€™m not facile with it and want to stick with Swift. I presume you have run those examples in Swift, so must have set up a Mac with the Mobile SDK and Xcode Swift :smile:

I canā€™t go further with the Swiftilicio.us site until I get the pod install to run.

Thanks,
Ben

Podfile is stlll not in the root project directory, put it there (use Finder) and cd to this folder in terminal and then run pod install, believe me, if the file is there it will install.

In addition, the Podfile contents should be JUST:

pod "Spark-SDK"

and not all this:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

target "Spark_SDK_First_Try" do
    pod "JGProgressHUD"
end
1 Like

Hi @ido
The project directory is there on the desktop, in the screenshot. Finder is open and you can see that the view is on the top level of the folder and that Podfile is right there. Am I confused about the term ā€œroot of the directoryā€? Is it not:

In a computer file system, and primarily used in the Unix and Unix-like operating systems, the root directory is the first or top-most directory in a hierarchy. It can be likened to the trunk of a tree, as the starting point where all branches originate from.

So, could you look at the screen shot and tell me if that Podfile is at the root of the directory according to what you mean, cause I think it is according to that definition. Thatā€™s all I have to go on for an explanation of root directory.

You can see in the screen shot that I have navigated Terminal to the directory that contains the file Podfile. Although I am there, I get the file not found error. Could you look at the screenshot of the Finder window and the Terminal and tellme what is wrong.

As for the file contents, you sent me to Swiftilicio.us page for Swift, and that is what that page said should be in the Podfile. So, I was just trying to follow the instructions you provided. If I donā€™t follow the instructions on Swiftilicio.us (there are several pages of Swift instructions), then what should I do to get the Mobile SDK running in Swift?

@ido, I am trying to get the Swift SDK running as you suggested. Iā€™m doing everthing I can on my own and spending hours reading the docs, the links in the docs and experimenting, but I am making no progress. The announcement said to come to this forum for help, so thatā€™s why Iā€™m here. If this is the wrong place to get help, just let me know.

file Podfile should reside in same directory as your <project name>.xcodeproj file.
you can use the command ls -l on shell to verify you see both of those files in the folder you are currently in, once thatā€™s the case run pod install or pod update. the swiftalico.us page contain the instructions on how to setup XCode environment settings to allow Obj-C SDK integration with Swift project, any SDK. It is not specific instructions for the Particle SDK.

I found that there is help for Pod if entered as Pod --help.

From there I learned that you can create a Podfile in the currently pointed to directory by typing Pod init. I did that and it created a second Podfile in my project root directory, right alongside the one I created. The file created with init is listed as a text file. The one I created is listed as a TextEdit Document. Neither has an extension but somehow they are different, which might explain why pod install could not find a pod file.

I put the line: pod ā€œSpark-SDKā€ in the file created by pod init. I ran pod install and got this error message:

Bendrixs-MacBook-Pro:Spark_SDK_First_Try bendrix$ pod install

[!] Invalid Podfile file: undefined local variable or method `ā€œSparkā€™ for #Pod::Podfile:0x007f8fc3af4600. Updating CocoaPods might fix the issue.

from /Users/bendrix/Desktop/Spark_SDK_First_Try/Podfile:1

-------------------------------------------

pod ā€œSpark-SDKā€

-------------------------------------------

Since I just installed Cocoapods yesterday, the suggested update of cocoapods is not likely to be the source of the problem.

SOLVED See revised post at the top of the page.

1 Like

Glad everything was solved.
Thanks Ben for summarising it up to help other users, I appreciate it.