Xcode didn't do anything signal SIGABRT - swift

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.

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()
}
}

Stripe Integrating Issues

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:.
}
}

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 2.0: Schedule background task to upload failed product uploads

I am developing an app which uploads a product (JSON) to server. Now, every product object consists of many images. A product is only uploaded to server if all images associated with that product have already been uploaded. In case all images for the product have not been uploaded, the product should be stored in 'PENDING' state in the mobile database (I am using Realm).
I want a background task to periodically (every 15 minutes) check the DB for such failed product uploads, check if all images associated with the product have now been uploaded and queue the product for upload to server.
This background task will execute ONLY when the app is running, not otherwise. The task should be launched at boot and killed on app close.
I found some relevant solutions (relating to NSTimer and background modes in iOS, etc.) but nothing addresses my problem directly. Please direct me in the right direction! Thanks!
Background modes are helpful when you need background tasks get executed when app is not running so thats not what you want. NSTimer can do a job here and you need to schedule it after application becomes active in app delegate and invalidate just after application enter background. A simple example might look like this:
var timer:NSTimer!
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
timer = NSTimer.scheduledTimerWithTimeInterval(60 * 15, target: self, selector: "uploadData", userInfo: nil, repeats: true)
return true
}
func applicationDidEnterBackground(application: UIApplication) {
timer.invalidate()
}
func applicationWillEnterForeground(application: UIApplication) {
timer = NSTimer.scheduledTimerWithTimeInterval(60 * 15, target: self, selector: "uploadData", userInfo: nil, repeats: true)
}
func uploadData(){
// Query unsychronzied data and send them to server here
}

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:.
}