Code Monkey home page Code Monkey logo

amplify-ios-getting-started's People

Contributors

jennapederson avatar kilo-loco avatar sebsto avatar thimslugga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

amplify-ios-getting-started's Issues

App crashing

Getting below error and iOS App crashed on launch itself

Initialized Amplify
Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file /Users/rajkumar/Developer/iOS Getting Started/Pods/AmplifyPlugins/AmplifyPlugins/Auth/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+ClientBehavior.swift, line 126
2020-09-17 00:42:35.868556+0530 iOS Getting Started[72386:229469] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file /Users/rajkumar/Developer/iOS Getting Started/Pods/AmplifyPlugins/AmplifyPlugins/Auth/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+ClientBehavior.swift, line 126

I am trying step by step from https://aws.amazon.com/getting-started/hands-on/build-ios-app-amplify/module-three/

  import UIKit
  import AmplifyPlugins
 import Amplify
  class Backend {

   static let shared = Backend()

   static func initialize() -> Backend {

   return .shared

}

private init() {
  // initialize amplify
  do {
    
    try Amplify.configure()
    try Amplify.add(plugin: AWSCognitoAuthPlugin())
    // in private init() function
    // listen to auth events.
    // see https://github.com/aws-amplify/amplify-ios/blob/master/Amplify/Categories/Auth/Models/AuthEventName.swift
    print("Initialized Amplify");
  } catch {
    print("Could not initialize Amplify: \(error)")
  }
    
    // let's check if user is signedIn or not
    Amplify.Auth.fetchAuthSession { (result) in
         do {
             let session = try result.get()
                    
    // let's update UserData and the UI
         self.updateUserData(withSignInStatus: session.isSignedIn)
                    
         } catch {
              print("Fetch auth session failed with error - \(error)")
        }
    }
    _ = Amplify.Hub.listen(to: .auth) { (payload) in

        switch payload.eventName {

        case HubPayload.EventName.Auth.signedIn:
            print("==HUB== User signed In, update UI")
            self.updateUserData(withSignInStatus: true)

        case HubPayload.EventName.Auth.signedOut:
            print("==HUB== User signed Out, update UI")
            self.updateUserData(withSignInStatus: false)

        case HubPayload.EventName.Auth.sessionExpired:
            print("==HUB== Session expired, show sign in UI")
            self.updateUserData(withSignInStatus: false)

        default:
            //print("==HUB== \(payload)")
            break
        }
    }
}



// MARK: - User Authentication

// signin with Cognito web user interface
public func signIn() {

    _ = Amplify.Auth.signInWithWebUI(presentationAnchor: UIApplication.shared.windows.first!) { result in
        switch result {
        case .success(_):
            print("Sign in succeeded")
        case .failure(let error):
            print("Sign in failed \(error)")
        }
    }
}

// signout
public func signOut() {

    _ = Amplify.Auth.signOut() { (result) in
        switch result {
        case .success:
            print("Successfully signed out")
        case .failure(let error):
            print("Sign out failed with error \(error)")
        }
    }
}

// change our internal state, this triggers an UI update on the main thread
func updateUserData(withSignInStatus status : Bool) {
    DispatchQueue.main.async() {
        let userData : UserData = .shared
        userData.isSignedIn = status   
    }
}

}

Mistake in tutorial: bad library in build.gradle

In 4 step of tutorial: https://aws.amazon.com/getting-started/hands-on/build-android-app-amplify/module-four/
In substep: "Add API Client Library to the Android Studio Project"

You instruct to add dependencies:

dependencies { implementation 'com.amplifyframework:aws-api:1.4.0' implementation 'com.amplifyframework:aws-auth-cognito:1.4.0' }

This dependencies are already added in previous step.
However, aws-api library is missing:

implementation 'com.amplifyframework:aws-api:1.17.1'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.