Go easy on me please. I'm not familiar with Swift and AWS. I'm trying to use AWS Authentication for user login. Using AWSCognitoAuthPlugin, I get this error:
An error occurred setting up Amplify: PluginError: Unable to decode configuration
Recovery suggestion: Make sure the plugin configuration is JSONValue
What I have on my Swift file is very generic, following the AWS guide to get set up. I have no UI for the login as of now. I'm seeing the error via log.
Here's my code:
import SwiftUI
import Amplify
import AWSAPIPlugin
import AWSDataStorePlugin
import AWSCognitoAuthPlugin
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
do {
Amplify.Logging.logLevel = .verbose
try Amplify.add(plugin: AWSCognitoAuthPlugin())
try Amplify.configure()
print("Amplify configured with auth plugin")
} catch {
print("An error occurred setting up Amplify: \(error)")
}
return true
}
}
#main
struct MyAmplifyAppApp: App {
#UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
I'm not using cocoa pods because that causes the import statement for amplify to not work. I'm following this guide from AWS:
https://docs.amplify.aws/lib/auth/getting-started/q/platform/ios#install-amplify-libraries
Stuck at Initialize Amplify Auth section last step.
I was also facing same error for few days, you just have added basic files to the project and now you need to define user pools for Amplify to add more data to both config files. You need to run these commands it will fix this issue. Please make sure you are in directory of your project.
amplify init // It will make sure you have basic setup added
amplify add auth // It will add auth data and user pools to config files
amplify push // It will push all the setup to amplify cloud
Hope it will fix this issue :)
Related
I am trying to add Google MLKit Translate into my SwiftUI Project. I am already using firebase via SPM and only after the initial launch get this error: -[FBLPromise HTTPBody]: unrecognized selector sent to instance 0x600001afa700
Here is my code:
App Delegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
FirebaseApp.configure()
...
let spanishRemoteTranslator = TranslateRemoteModel.translateRemoteModel(language: .spanish)
if ModelManager.modelManager().isModelDownloaded(spanishRemoteTranslator) {
print("Spanish Translator Downloaded")
}else {
print("Downloading Spanish Translator")
ModelManager.modelManager().download(spanishRemoteTranslator, conditions: ModelDownloadConditions(allowsCellularAccess: true, allowsBackgroundDownloading: true))
}
return true
}
Then I call it like so:
if ModelManager.modelManager().isModelDownloaded(spanishModel) {
Translator.translator(options: englishSpanishTranslator).translate(buis.name!) { translatedText, error in
if error == nil {
if let translatedText = translatedText {
name = translatedText
}else {
print("error = \(error)")
}
}else {
print("error = \(error)")
}
}
}else {
print("error = Spanish not downloaded")
}
I have also tried using the built in FirebaseMLKitDownload and that doesn't have translator. What is going on?
Probably an author of this post found solution of this problem (judging by the comment) but I decided to write this post because few hours ago during taking my first steps with Firebase I had the same error. I hope my post may be helpful for each other.
I had no idea how to find solution but after few hours of debugging I noticed that the problem occurs when I had initialized project with Firebase using dependency manager built-in in the Xcode and then I tried to initialize Firestore using CocoaPods. To be more specific, first thing I do was Firebase installation using this one:
Then, I started using CocoaPods like:
$ pod init
$ vim Podfile // adding 'firebase/firestore' dependency or specific line from https://github.com/firebase/firebase-ios-sdk
$ pod install
$ open <ProjectName>.xcworkspace
In the next step, I tried to check basic Firestore operations like creating collection and documents with data and when I run the app - I got similar error. It was an exception during app run.
I think in my case the problematic thing was possible duplicates because of supplying the project with a Firebase (with all dependencies) twice.
So, I removed dependency installed from the Xcode manager. In my Info.plist there is no dependencies:
Then, from the terminal I removed Pods directory and just called an update.
$ rm -rf Pods
$ pod update
All dependencies were re-installed and workspace has been recreated.
Now, after these steps everything works fine.
My app was working normally since today.I already included Firebase Storage in my Android Flutter App and it works after that today I get AppCheck Errors suddenly. I was not include App Check for our project or not enforced in settings. After that I was following the official documentation for initialization appcheck : https://firebase.flutter.dev/docs/app-check/usage.
This is my Kotlin MainActivity:
import android.os.Bundle
import com.google.firebase.FirebaseApp
import com.google.firebase.appcheck.FirebaseAppCheck
import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory
import io.flutter.embedding.android.FlutterActivity
class MainActivity : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
FirebaseApp.initializeApp(/*context=*/ this);
val firebaseAppCheck = FirebaseAppCheck.getInstance()
firebaseAppCheck.installAppCheckProviderFactory(
DebugAppCheckProviderFactory.getInstance())
super.onCreate(savedInstanceState)
}
}
and this is my main():
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await FirebaseAppCheck.instance.activate();
runApp(MyApp());
}
I also added this to my app/build.gradle
dependencies {
implementation 'com.google.firebase:firebase-appcheck-debug:16.0.0-beta01'
}
When I make a request to firebase storage, I would expect something like this in my console:
D DebugAppCheckProvider: Enter this debug secret into the allow list in the Firebase Console for your project: 123a4567-b89c-12d3-e456-789012345678
Instead, I'm getting an error:
2021-11-21 18:11:51.442 2091-3452/com.sekspir.grind4gain W/ExponenentialBackoff: network unavailable, sleeping.
2021-11-21 18:11:53.500 2091-3452/com.sekspir.grind4gain W/StorageUtil: Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.
2021-11-21 18:12:11.136 2091-3633/com.sekspir.grind4gain V/NativeCrypto: SSL handshake aborted: ssl=0xdaa42da8: I/O error during system call, Connection reset by peer
Did I miss something here? I am using a real Android device with flutter debug build.
This is Firestore AppCheck Stats looks both of request income
But in Storage session there are not any request fail or success.
Can you double check that you correctly enabled the enforcement ?
It is required to work with Firebase Storage solutions.
Are you using your app in "PWA" mode or in "Native" mode ?
The Recaptcha may be mandatory depending on how your app is distributed.
await FirebaseAppCheck.instance.activate(
webRecaptchaSiteKey: 'recaptcha-v3-site-key',
);
I'm not sure about your implementation of the appcheck-debug dependency on the Android Native side.
Since it's already implemented by the Flutter library itself, you should remove it.
Personal note : I had troubles with FirebaseAppCheck on some devices, while it was working perfectly on other devices.
This library is still in beta and I would recommend to wait before using it in production.
I've been running tests on a Vapor project, which have been running happily. With no apparent changes, and none to the setup and breakdown routines, now they refuse to start, with the error
Vapor/Application.swift:154: Fatal error: Application.shutdown() was not called before Application deinitialized.
2021-08-28 15:15:45.136991+0700 xctest[9353:93515] Vapor/Application.swift:154: Fatal error: Application.shutdown() was not called before Application deinitialized.
I've got auto migrate turned on, and I've tried blowing away the docker psql instance, and recreating it. The app runs fine on localhost, and on the remote server: I just can't get tests to start and run.
There's only one test document, and it starts with this:
#testable import App
import XCTVapor
import Fluent
final class NewTests: XCTestCase {
static var app : Application!
static var stdPass = "12345"
var app = NewTests.app
var stdPass = stdPass
// SETUP AND TEARDOWN =================================================
override func setUp() { NewTests.app = try! Application.testable(); app = NewTests.app }
override func tearDown() { NewTests.app.shutdown() }
func testBasicTournamentCreate() throws {
…
}
There are two tests: one is basic, and the other is very long, since we have to replicate the conditions in a complex situation, with random input from a number of users interacting with the app. That doesn't seem to be the issue, since if I run only the simple, short test, I get the same result.
The targets in package.swift look like this:
.target(name: "Run", dependencies: [.target(name: "App")]), // comment what follows
.testTarget(name: "AppTests", dependencies: [
.target(name: "App"),
.product(name: "XCTVapor", package: "vapor"),
])
I remember having a similar problem, but some combination of a recreation of the database, cleaning the build folder and eventually a restart fixed it. I've tried all that, and no dice...
It's likely that the test app can't connect to a database. Do double check your database configuration and make sure it matches whatever test database you're trying to connect to.
The easiest way to find out what's going on is to wrap any try's in a do/catch and see what the error is. What's happening is something is throwing an error, causing the test case to exit and deinitialise the Application instance before your call to shutdown has been triggered
The culprit was a typo in a migration, but in a string literal field name (so the compiler didn't catch it), and in the revert clause, so it happened only after the db had been initialized. This meant that I eliminated the migration, because after the test had run, I could see the complete schema.... ah well.
I deployed my ASP.NET application to a remote server with a hosting company, and when i try to send data from Postman, i get the internal server error with no definite error message. I have set custom error mode to off in the web config file. please can anyone help me? I have checked for several solutions but nothing.
PS: i am new to ASP.NET deployment with other companies apart from Azure
In this case, you should log error to file to see what issues in deployment mode.
This way i implemented global error log.
public class ExceptionHandlingAttribute : ExceptionFilterAttribute
{
public override void OnException(HttpActionExecutedContext context)
{
//Log Critical errors
// You can use log4net library and configure log folder
}
}
In WebApiConfig.cs file you register it.
public static void Register(HttpConfiguration config)
{
// .....
config.Filters.Add(new ExceptionHandlingAttribute());
}
I am trying to get the Bluemix Cordova Hello World sample working with IBMPushNotifications Service. I have installed the cordova plugins and if I run cordova plugin list I see:
ibm-mfp-core 1.0.10 "MFPCore"
ibm-mfp-push 1.0.12 "MFPPush"
My index.js initialization code looks like this:
onDeviceReady: function() {
BMSClient.initialize(app.route, app.guid);
BMSClient.registerAuthenticationListener("MyRealm", customAuthenticationListener);
// alert("******** ABOUT TO CALL MFPPush.registerDevice **************");
// MFPPush.registerDevice(iosPushSettings, pushSuccess, pushFailure);
MFPPush.registerDevice({}, pushSuccess, pushFailure);
I do have the MAS customAuthentication service running and working.
I am running the code on an attached iPad via Xcode. I've added some debugPrint statements inside the plugin swift file and see the following messages in the Xcode Console:
"Inside Register Device!!!!!!!"
"Inside registerNotificationsCallback"
"Settings Parameter is not null"
"settings.count == 0"
"about to set notificationSettings"
"About to registerForRemoteNotifications"
"Called registerForRemoteNotifications"
I am not a swift or iOS developer, so I am pretty ignorant on debugging and working with iOS apps. I tried to set breakpoints in the AppDelegate.m file and appears that the code is hitting the breakpoint in didRegisterForRemoteNotificationsWithDeviceToken and I think a token value is getting set. However, I never see my debugPrint code getting triggered in the CDVMFPPush.swift file inside
func didRegisterForRemoteNotifications(deviceToken: NSData) {
debugPrint("Inside didRegisterForRemoteNotifications")
or inside
func didFailToRegisterForRemoteNotifications(error: NSError) {
debugPrint("Inside didFailToRegisterForRemoteNotifications")
As far as I can tell, I have set up the APNS Cert and provisioning profile and I have uploaded my sandboxAPNS.p12 file without any errors into my Bluemix Push service.
On the Bluemix Push Dashboard, if I try to send a push notification to all devices, I receive the following error:
Internal server error. No devices found
I also see PushNotifications enabled in the capabilities tab for my app in XCode.
I am trying to determine why I never see my debugPrint statements for the didRegister or didFailToRegister and why Bluemix does not see my device. Thanks for any suggestions on how to debug and again my apologies for my ignorance on swift and XCode.
JT
OK, I got Push notifications working. It turns out I needed to modify the AppDelegate.m file as per the docs and the Git readme:
// Register device token with Bluemix Push Notification Service
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
[[CDVMFPPush sharedInstance] didRegisterForRemoteNotifications:deviceToken];
}
// Handle error when failed to register device token with APNs
- (void)application:(UIApplication*)application
didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
[[CDVMFPPush sharedInstance] didFailToRegisterForRemoteNotifications:error];
}
// Handle receiving a remote notification
-(void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[[CDVMFPPush sharedInstance] didReceiveRemoteNotification:userInfo];
}