Stripe Integrating Issues - swift

I installed 'Stripe' in my project. However, when I follow the directions on Stripe's website to integrate and 'import Stripe' in my AppDelegate, it says 'no module' and doesn't work/comes as an error. Am I doing something wrong?

Stripe's Library is in Obj-C you will need to add a Bridging Header to be able to import it to a swift project
Extensive guide :- https://www.appcoda.com/ios-stripe-payment-integration/
Also : - https://stackoverflow.com/a/30635582/6297658 might be helpful

Try this:
update Podfile
use_frameworks!
target '**{YOUR_PROJECT_NAME}**' do
pod 'Stripe'
end
delete Podfile.lock and Pods. After install pod
your sample code AppDelegate.swift
import UIKit
import Stripe
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
STPPaymentConfiguration.sharedConfiguration().publishableKey = "pk_test_6pRNASCoBOKtIshFeQd4XMUh"
// do any other necessary launch configuration
return true
}
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}

Related

Local notification pull into background function triggering

when I terminate my app into twice tap on home button then how can I call my function in background service on swift 4.
because I work on local push notification , after API calling then getting data and that's data put into notification.
I am not entirely sure this is what you mean, but if you want to call a function/do something right before your app enters the background(what happens when someone double clicks the home button) you can use the default applicationWillResignActive(_:) or applicationDidEnterBackground(_:) function in the AppDelegate class. See the apple docs for more information about app states and functions.
If you want to execute code when the app terminates, use applicationWillTerminate(_:).
So in AppDelegate.swift(I deliberately left the original Xcode default comment in for clarification):
class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
yourGoToBackgroundFunction()
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
yourSaveDataFunction()
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
yourSaveDataFunction()
}
}

Xcode didn't do anything signal SIGABRT

I've just installed Xcode and tried to run an empty app.It shows this bug, even though I didn't even touch it!
The code:
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
The way to fix this was to add at least something in your app.It doesn't matter what!For me, I just added a variable and it worked.

How and where do I execute a function after the user closes an app?

Can I include a function that runs once if the user closes the app? If so, where should I put that function because I don't know which view controller the user will be closing the app from. What's the solution?
In AppDelegate.swift
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

iOS Application with Firebase doesn't start with a slow internet connection

Since I upgraded to the new Firebase, my application doesn't start with a slow internet connection. It does when it is has a good connection and also when it hasn't got any connection at all. I think that I've set up everything properly since it wouldn't work at all if I made a mistake with the setup.
Here's my AppDelegate code:
import UIKit
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptionslaunchOptions: [NSObject: AnyObject]?) -> Bool {
UITabBar.appearance().tintColor = UIColor.redColor()
FIRApp.configure()
FIRDatabase.database().persistenceEnabled = true
return true
}
}
iOS includes a mechanism called watchdog, which will terminate any application that fails to launch in a certain time window. Any blocking task you do in application(_:didFinishLaunchingWithOptions:) has the potential to cause your app to be terminated if it takes too long. You should consider performing such tasks asynchronously.
You can put breakpoints or print statements in your code to determine which line is taking too long.

Swift: Run a code once a while whenever app is closed

I've an app that has to run a code once a while whenever app isn't running. Is this possible? if yes Any help will be appreciated
Your app can run in the background several minutes.
I would suggest to override one of these methods to achieve your goal:
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}