Skip to content

Commit

Permalink
DOCSP-4379 Validate and clarify intro in README (#173)
Browse files Browse the repository at this point in the history
* DOCSP-4379 Validate and clarify intro in README

- Ran through the steps in README to validate their current accuracy
- Some improvements/clarifications made

* Addressing comments
  • Loading branch information
cbush authored Apr 26, 2019
1 parent ca95189 commit 09a061f
Showing 1 changed file with 47 additions and 27 deletions.
74 changes: 47 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The official [MongoDB Stitch](https://stitch.mongodb.com/) SDK for iOS/Swift.

## Installation

### XCode/iOS
### Xcode/iOS

#### CocoaPods

Expand All @@ -30,7 +30,7 @@ The official [MongoDB Stitch](https://stitch.mongodb.com/) SDK for iOS/Swift.
$ gem install cocoapods
```

> CocoaPods 1.6.0+ is required to build the Stitch iOS SDK 5.0+.
- Note: CocoaPods 1.6.0+ is required to build the Stitch iOS SDK 5.0+.

To integrate the iOS SDK into your Xcode project using CocoaPods, specify it in your `Podfile`:

Expand Down Expand Up @@ -69,25 +69,33 @@ Open the `.xcworkspace` file generated by `pod install` to access your project w
#### Set up an application on Stitch
1. Go to [https://stitch.mongodb.com/](https://stitch.mongodb.com/) and log in to MongoDB Atlas.
2. Create a new app in your project with your desired name.
3. Go to your app in Stitch via Atlas by clicking Stitch Apps in the left side pane and clicking your app.
3. Copy your app's client app id by going to Clients on the left side pane and clicking copy on the App ID section.
4. Go to Providers from Users in the left side pane and edit and enable "Allow users to log in anonymously".
3. Go to your app in Stitch via Atlas by clicking 'Stitch' in the left side pane and clicking your app.
3. Copy your Stitch App ID from the top of the left side pane.
4. Enable anonymous authentication by going to the Users page in the left side pane, selecting the Providers tab, and enabling the "Allow users to log in anonymously" option.

#### Set up a project in XCode/CocoaPods using Stitch
#### Set up a project in Xcode/CocoaPods using Stitch

1. Download and install [Xcode](https://developer.apple.com/xcode/).

- Note: Xcode 10.1 (10B61) is currently the maximum supported version. To install an old version of Xcode, see [https://developer.apple.com/download/more/](https://developer.apple.com/download/more/).

1. Download and install [XCode](https://developer.apple.com/xcode/)
2. Create a new app project with your desired name. Ensure that Swift is the selected language.

- Note: iOS 11.0 is the minimum iOS Deployment Target.

3. Navigate to the directory of the project in a command line, and run `pod init`.
4. In the `Podfile` that is generated, add the following line under the dependencies for your app target:

```ruby
pod 'StitchSDK', '= 5.1.0'
```

5. Run `pod install`
6. Open the generated `.xcworkspace` file
7. Your app project will have all the necessary dependencies configured to communicate with MongoDB Stitch.
8. To use basic Stitch features, `import StitchCore` in a source file.
See above for the list of optional Stitch service pods that you may add to your Podfile.

5. Run `pod install`.
6. Open the generated `.xcworkspace` file. Your app project will have all the necessary dependencies configured to communicate with MongoDB Stitch.
7. To use basic Stitch features, `import StitchCore` in a source file.
8. To create BSON documents and BSON values like ObjectId, `import MongoSwift` in a source file.
9. To access a remote MongoDB instance via Stitch, `import StitchRemoteMongoDBService` in a source file.

#### Using the SDK
Expand All @@ -99,17 +107,20 @@ Open the `.xcworkspace` file generated by `pod install` to access your project w
// at the top of the file
import StitchCore

// ...

// in `application(_:didFinishLaunchWithOptions)`
do {
_ = try Stitch.initializeDefaultAppClient(
withClientAppID: "your-client-app-id"
)
print("Successfully initialized default Stitch app client!");
} catch {
print("Failed to initialize MongoDB Stitch iOS SDK: \(error)")
// note: This initialization will only fail if an incomplete configuration is
// passed to a client initialization method, or if a client for a particular
// app ID is initialized multiple times. See the documentation of the "Stitch"
// class for more details.
print("Failed to initialize MongoDB Stitch iOS SDK: \(error)")
}
```

Expand All @@ -121,26 +132,26 @@ Open the `.xcworkspace` file generated by `pod install` to access your project w
```

##### Logging In
1. We enabled anonymous log in, so let's log in with it; add the following anywhere in your code:
1. We enabled anonymous log in, so let's log in with it! Add the following anywhere in your code:

```swift
let client = Stitch.defaultAppClient!

print("logging in anonymously")
client.auth.login(withCredential: AnonymousCredential()) { result in
switch result {
case .success(let user):
print("logged in anonymous as user \(user.id)")
DispatchQueue.main.async {
// update UI accordingly
}
case .failure(let error):
print("Failed to log in: \(error)")
}
}
switch result {
case .success(let user):
print("logged in anonymous as user \(user.id)")
DispatchQueue.main.async {
// update UI accordingly
}
case .failure(let error):
print("Failed to log in: \(error)")
}
}
```

2. Now run your app in XCode by going to product, Run (or hitting ⌘R).
2. Now run your app in Xcode by going to product, Run (or hitting ⌘R).
3. Once the app is running, open up the Debug Area by going to View, Debug Area, Show Debug Area.
4. You should see log messages like:

Expand All @@ -151,7 +162,7 @@ logged in anonymously as user 58c5d6ebb9ede022a3d75050

##### Executing a Function

1. Once logged in, executing a function happens via the StitchClient's `callFunction()` method
1. Once logged in, you can execute a [Stitch Function](http://docs.mongodb.com/stitch/functions) with the StitchClient's `callFunction()` method:

```swift
client.callFunction(
Expand All @@ -166,15 +177,24 @@ logged in anonymously as user 58c5d6ebb9ede022a3d75050
}
```

2. If you've configured your Stitch application to have a function named "echoArg" that returns its argument, you should see a message like:
2. If you've configured your Stitch application to have a function named "echoArg" that returns its argument, i.e.:

```javascript
// Stitch Function called 'echoArg'
exports = function(arg) {
return arg;
};
```

Then you should see a message in the Xcode Debug Area like:

```
String result: Hello world!
```

##### Getting a StitchAppClient without Stitch.defaultAppClient

In the case that you don't want a single default initialized StitchAppClient, you can use the following with as many client app IDs as you'd like to initialize clients for a multiple app IDs:
In the case that you don't want a single default initialized StitchAppClient, you can use the following with as many client app IDs as you'd like to initialize clients for multiple app IDs:

```swift
do {
Expand Down

0 comments on commit 09a061f

Please sign in to comment.