Post

Replies

Boosts

Views

Activity

How do you allow tasks that take longer than the 30 seconds allowed in the background thread to continue performing until done?
I am making a video sharing app, and in my app I am trying to upload videos to firebase. When I try to upload a video that is less than 1 minute long it works perfectly fine, but when I try to upload a video that is longer than 1 minute it does not work. I think the reason for this is because background threads only allow 30 seconds before it is terminated and it gives me this error: [BackgroundTask] Background Task 27 ("GTMSessionFetcher-firebasestorage.googleapis.com"), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this. After I realized I was getting this error I tried to implement the UIApplication.endBackgroundTask(_:) to extend the amount of time that this process can finish and I tried using this which I got from apples documentation:     func saveMovie(path: String, file: String, url: URL) {         var backgroundTaskID: UIBackgroundTaskIdentifier = UIBackgroundTaskIdentifier.invalid         // Perform the task on a background queue.         DispatchQueue.global(qos: .utility).async {             // Request the task asseration and save the ID             backgroundTaskID = UIApplication.shared.beginBackgroundTask(withName: "Finish doing this task", expirationHandler: {                 // End the task if time expires                 UIApplication.shared.endBackgroundTask(backgroundTaskID)                 backgroundTaskID = UIBackgroundTaskIdentifier.invalid             })             // Send the data synchronously             do {                 let movieData = try Data(contentsOf: url)                 self.storage.child(path).child("\(file).m4v").putData(movieData)             } catch let error {                 fatalError("Error saving movie in saveMovie func. \(error.localizedDescription)")             }             //End the task assertion             UIApplication.shared.endBackgroundTask(backgroundTaskID)             backgroundTaskID = UIBackgroundTaskIdentifier.invalid         }     } Unfortunately this did not work and I am still getting the same error. I am now stuck and unsure how I can allow this process to finish before background task terminates itself. Does anybody know how to allow a long-running task like this finish before it is terminated? Thanks in advance for any help!
1
0
6.0k
Dec ’21
How do you upload a movie URL to a server?
I am trying to upload a movie url to firebase and firebase is telling me "Invalid url pair". I think the reason for this is because in my console I am getting an error that says: Failed to issue sandbox extension for file I'm not sure why but I don't think apple allows you to upload a movie url to a server for some reason? How do you get around this? I already tried using CFURLStartAccessingSecurityScopedResource(_) which I saw from another answer:         picker.dismiss(animated: true)         // Get the movie URL from camera         let movieURL = info[.mediaURL] as! CFURL         // allow access to the movieURL.         CFURLStartAccessingSecurityScopedResource(movieURL)         // Upload the url to firebase.         Storage.storage().reference().child("WORK").child("YEET").putFile(from: movieURL as URL, metadata: nil) { metadata, error in             if let error = error {                 print("There was an error \(error)")             } else {                 print("Success")             }             // Stop allowing access to the movieURL             CFURLStopAccessingSecurityScopedResource(movieURL)         }     } And it didn't work :(. How do i allow access to a movie URL so I can upload it to firebase? Or maybe there is something else wrong? Idk anything helps, thanks in advance!
1
0
1.3k
Dec ’21
UICollectionViewCell improperly sizes itself after calling reloadData()
I have a UICollectionView in my ViewController. This collectionView has a dynamic height so depending on how much text is inside the collectionView it will resize the height. This works perfectly fine I can click all the buttons, scroll up or down, etc, but the problem is that when I call reloadData(), the collectionViewCells stack on top of each other and i'm not sure why. Here is a picture of the collectionView before reloadData() is called: [https://ibb.co/fSmM9q3) (Sorry it was giving me an error for this image so here is a link for it) Here is the picture after I call reloadData(): Here is my Custom Collection VIew Code:         public let bottomRefresh = CollectionViewBottomRefresh()   init() {     let layout = UICollectionViewFlowLayout()     layout.minimumLineSpacing = 0     layout.minimumInteritemSpacing = 0     layout.scrollDirection = .vertical     layout.estimatedItemSize = CGSize(width: UIScreen.main.bounds.width, height: 50)     super.init(frame: .zero, collectionViewLayout: layout)     alwaysBounceVertical = true     backgroundColor = .systemBackground     delaysContentTouches = false     showsVerticalScrollIndicator = false     register(PostView.self, forCellWithReuseIdentifier: "post")   }       required init?(coder: NSCoder) {     fatalError("init(coder:) has not been implemented")   }       override func touchesShouldCancel(in view: UIView) -> Bool {     if view is UIButton || view is UITextField {       return true     }     return super.touchesShouldCancel(in: view)   } } Here is my Collection View Cell Code:       // Sets a requried width and a dynamic height that changes depending on what is in the cell. So we can have searchbar as first cell heigh 50, and post in other cells with height of view.bounds.width.   override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {     let targetSize = CGSize(width: layoutAttributes.frame.width, height: 0)     layoutAttributes.frame.size = contentView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)     return layoutAttributes   }       private func addConstraints() {     kuduAppTeamDeleteButton.height(30)     kuduAppTeamDeleteButton.width(UIScreen.main.bounds.width / 4)     kuduAppTeamDeleteButton.bottom(to: commentsButton)     kuduAppTeamDeleteButton.leftToRight(of: commentsButton, offset: 5)           imageViewButton.width(UIScreen.main.bounds.width)     imageViewButton.height(UIScreen.main.bounds.width * 9/16)     imageViewButton.topToSuperview()           infoButton.leftToRight(of: titleLabel, offset: 6)     infoButton.topToBottom(of: imageViewButton, offset: 15)     infoButton.width(30)     infoButton.height(30)           titleLabel.horizontalToSuperview(insets: UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 40))     titleLabel.topToBottom(of: imageViewButton, offset: 5)     titleLabel.height(min: 50)           likeButton.topToBottom(of: titleLabel, offset: 10)     likeButton.trailingToSuperview(offset: 10)     likeButton.height(32)     likeButton.width(32)           profile.leadingToSuperview(offset: 5)     profile.topToBottom(of: titleLabel, offset: 10)     profile.widthToSuperview(multiplier: 0.4)           likeCount.trailingToLeading(of: likeButton, offset: -5)     likeCount.topToBottom(of: titleLabel, offset: 15)           followButton.topToBottom(of: titleLabel, offset: 5)     followButton.trailingToLeading(of: likeCount, offset: -10)     followButton.height(50)     followButton.width(UIScreen.main.bounds.width / 4)           date.bottom(to: commentsButton, offset: -5)     date.trailingToSuperview(offset: 5)           commentsButton.topToBottom(of: profile, offset: 10)     commentsButton.leadingToSuperview(offset: 5)           line.horizontalToSuperview()     line.bottom(to: commentsButton)     line.height(1)           contentView.bottom(to: line)     contentView.widthToSuperview()   } Thanks in advance!
3
0
4.1k
Dec ’21
How do you change layoutAttributes in a collectionView
I have a UICollectionView and I want to change the layoutAttributes of my collectionView. I am calling this function: override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {         print("Layout has been changed lit fool.")         let targetSize = CGSize(width: 10, height: 40)         layoutAttributes.frame.size = contentView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)     } For some reason my layoutAttributes are not being effected by this code. No matter what variable I change my targetSize to, the collectionView size stays the same. The print statement is running, so I know that this function is getting called correctly, its just the layoutAttributes don't change. How do I get my layoutAttributes to change from this function?
0
0
650
Dec ’21
How do you get an override function to be called on command?
I have a function: override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {         print("Layout has been changed.")         let targetSize = CGSize(width: layoutAttributes.frame.width, height: 40)         layoutAttributes.frame.size = contentView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)         return layoutAttributes     } This function changes the frame of my UICollectionViewCells and it is working exactly how it is supposed to. The problem is that this function is only called when the view loads for the first time, but when I call reloadData() on my collectionView this function is not called. Because this function is not called it screws up the sizes of my collectionView. My question is how do I get this function to run when I call reloadData() on my collectionView?
0
0
663
Dec ’21
How do I pass in my custom collectionView instead of using the default collectionView?
I have a function:          // Cant pass it directly into the init because it is an override init :/     override init() {         super.init()     }          required init?(coder: NSCoder) {         fatalError("init(coder:) has not been implemented")     }          weak var delegate: layoutDelegate?              private var cache: [UICollectionViewLayoutAttributes] = []          private var contentHeight: CGFloat = 0          private var contentWidth: CGFloat {         guard let collectionView = collectionView else {             print("Collectionview not found")             return 0         }         let insets = collectionView.contentInset         return collectionView.bounds.width - (insets.left + insets.right)     }          override var collectionViewContentSize: CGSize {         return CGSize(width: contentWidth, height: contentHeight)     }          override func prepare() {         guard             cache.isEmpty,             let collectionView = collectionView         else { print("No Collectionview rip"); return }                  let columnWidth = contentWidth                  for item in 0..<collectionView.numberOfItems(inSection: 0) {             let indexPath = IndexPath(item: item, section: 0)                          let postHeight = delegate?.collectionView(_collectionView: collectionView, heightForPostAtIndexPath: indexPath) ?? 200             let height = postHeight             let frame = CGRect(x: 0, y: 0, width: columnWidth, height: height)                          let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)             cache.append(attributes)                          contentHeight = max(contentHeight, frame.maxY)         }     }          override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {         var visibleLayoutAttributes: [UICollectionViewLayoutAttributes] = []                  // Loop through the cache and look for items in the rect         for attributes in cache {             if attributes.frame.intersects(rect) {                 visibleLayoutAttributes.append(attributes)             }         }         return visibleLayoutAttributes     }          override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {         return cache[indexPath.item]     } } I have my own collectionView called CustomCollectionView and I want to pass it into this function to use instead of the default collectionView that this function gives me because it is of type UICollectionViewLayout. However I am unsure how I am supposed to pass in my own collectionView because this function is using an override init() and I am not able to pass variables into it. Question: How do I pass a variable into this class so that I can use my customCollectionView instead of the default collectionView
1
0
725
Dec ’21
What are some good cloud storage options for storing videos?
I am making a video sharing app and I am looking for a good cloud storage service that I can upload my videos to and store them. I was previously using Firebase Cloud to store my videos, but I ran into a problem with Firebase and decided it will not work for what I am trying to do. So I decided to switch my cloud storage and I am having a hard time finding something that will work. Question: What are some good cloud storage options for storing videos? Or is there a better way to store videos other than a cloud storage service? The app is very similar to Youtube and the average video length will be around 10 mins if that helps at all. P.S The problem I am having with Firebase storage is that the videos never get uploaded to Firebase if the user closes out of the app during the upload. None of the IOS background options work either.BGProcessingTask and URLSessionUploadTask do not work to finish uploading the video in the background because Firebase does not allow you to pausing uploading during sessions to finish BGProcessingTask, and Firebase does not give you a URL to upload the video to finish URLSessionUploadTask.
1
0
1.1k
Jan ’22
How does apple encrypt binary data when you upload an app to the app store?
I read this answer here which says that apple will encrypt your apps binary when you upload it to the app store. First of all, How exactly does encrypting binary data work when you can download the entire application directly on your device? Once you download the app on your device can you not just disassemble the exact binary from the app? Or is this disassembled binary code encrypted? Second, If this disassembled binary code is encrypted, then doesn't this mean apple is slowing down all apps on the app store because it has to decrypt every single instruction from the binary before running it on the device? Also what's the problem with hard coding sensitive information into source code if it will be encrypted?
2
0
2k
Oct ’22
How to get blue SMS texts for your business?
I need to implement SMS into my business. I could use Twilio, but Twilio doesn't give me blue text messages and I would really like our business to be able to send blue text messages to other iPhone users instead of that nasty green color... Is there an API that allows you to automatically send SMS from iMessage so I can send blue text messages to other iPhone users? Or is this not possible and the only way to get blue text messages is to send them manually through a business iPhone?
1
0
2.3k
Oct ’22