#StackBounty: #ios #swift #avfoundation #avcomposition #avvideocomposition AVPlayer resizeAspect works only properly on iPhone X

Bounty: 50

resizeAspect as the video gravity only works properly for me, when using an iPhone X.

For some reasons, the black aspect bar gets only added to the top and not to the bottom. This is how it looks like when I’m not using an iPhone X (the image is white)


This is how it should look like:

normal state

As you can see, on the iPhone X, everything looks clean and balanced as expected.

This is how I play the video:

    avPlayerLayer = AVPlayerLayer(player: avPlayer)
    avPlayerLayer.frame = PreviewLayer.bounds
    avPlayerLayer.videoGravity = .resizeAspect //Will automatically add black bars

    PreviewLayer.layer.insertSublayer(avPlayerLayer, at: 0)
    let playerItem = AVPlayerItem(url: video)
    avPlayer?.replaceCurrentItem(with: playerItem)

Get this bounty!!!

#StackBounty: #ios #swift #xcode #cocos2d-iphone How to delete photos added in specific albums but not in others?

Bounty: 100

I wonder in swift and xcode: how do I delete photos added in specific albums but not in others. For example photos added in camera rolls but not in other albums? I know in principle, apple make it only a reference link of the same photo in camera rolls in other album, so if delete in one, you will delete in all others. But would it be possible to make any way around it? For example copy it as a file copy to new album with different names?
Any one have any idea how to work around with it ?

Thank you,

Get this bounty!!!

#StackBounty: #ios #swift #usernotifications #unusernotification User notification are restricted to a limit in iOS app how to send unl…

Bounty: 50

I am working on a alarm app project(Click for github link) this code is working fine but problem is notifications are limited to approximately 64 at time so I am unable to send continues notification until user respond to notification. I read some the apple restricts local notification to only 64 but I have seen many apps on apple store those are sending notification continuously here few links from apple store.


Anyone help to understand how these app are able to send continuous and I tried these app are sending notification until user respond to app (for more then 1 hr I checked). Below is the code for setting single notification.

    let comingSunday =  findNext("Sunday", afterDate: fireDate.adding(minutes: item))
    let triggerDate = Calendar.current.dateComponents([ .year, .month, .weekday, .hour, .minute, .second], from: comingSunday!)
    let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate, repeats: alarm.repeatAlarm)

    let request = UNNotificationRequest(identifier: "(alarm.uuid)0(item)", content: notificationContent, trigger: trigger)
    UNUserNotificationCenter.current().add(request) { (error) in
                         if let error = error {
                           print("Unable to add notification request, (error.localizedDescription)")

Get this bounty!!!

#StackBounty: #ios #swift #uitableview #autolayout #ios11 Unwanted UITableView reload animation when navigating from iOS 11 search cont…

Bounty: 100

I have a view controller with a tableview containing a list of chats, a search controller enbeded in the navigation item (iOS 11 feature)

let searchController = UISearchController(searchResultsController: nil)
searchController.dimsBackgroundDuringPresentation = false
navigationItem.searchController = searchController
definesPresentationContext = true

When the user taps a chat in the table view the app pushes a new view controller with another table view containing messages for that chat. That works like it is supposed to:

enter image description here

The problem is that when the user activates the search controller, find some chat and taps it, the pushed view controller containing table view with the chat messages does some really strange animation with the table view that should not happen:

enter image description here

I load the data before the actual navigation and bind it to the table view in viewDidLoad using just reload() on the table view. The problematic table view uses auto layout and custom cells.

The problem is very similar to UITableView has unwanted animation when reloadData is called but for me it only happens when the iOS 11 search controller is active.

Edit: If I remove tableView.rowHeight = UITableViewAutomaticDimension and use a fixed height using func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat the problem is still there

Get this bounty!!!

#StackBounty: #ios #swift #unit-testing #xctest #eventkit How to test a function/computed property that uses the User's calendar/ev…

Bounty: 50

I’m developing a calendar app where I’m struggling to create tests for the functions that utilize the calendars on the users device. The
calendar: EKCalendar variable is taken from the users event store so when the unit tests run on XCode’s emulator they fail as the calendar doesn’t exist. Using my personal device works but then the tests would fail on our build server.

What are good approaches for testing functions that utilise resources on a users physical device?

    ///Return the user's name. If this hasn't been saved extract their name from their Enterprise calendar and save it.
static var name: String? {
    if let savedName = defaults.string(forKey: "name") {
        return savedName

    // calendar is a specific EKCalendar members of my company will have.
    guard let calendar = MeetingsFetcher().getUserEnterpriseCalendar().first,
        let parsedName = calendar.title.firstMatch(from: Regex.organizerNameFromEKCalendar) else {
            return nil
    defaults.set(parsedName, forKey: "name")
    return parsedName

Get this bounty!!!

#StackBounty: #objective-c #swift #protocols Parent-child protocol relationship and ObjC availability

Bounty: 100

I can’t get the following code to work:

@objc protocol Child { }

@objc protocol Parent {
    var child: Child { get }

class ChildImpl: Child { 
    func doSomething() { }

class ParentImpl: Parent {
    let child = ChildImpl()

    // this would solve the problem, however can't access the ChildImpl members
    // that are not part of the protocol
    // let child: Child = ChildImpl()

    // as well as this, however maintaining two properties is an ugly hack
    // var child: Child { return childImpl }
    // private let childImpl = ChildImpl()

The errors I get:

Playground execution failed: error: Tests.playground:3:7: error: type ‘ParentImpl’ does not conform to protocol ‘Parent’
class ParentImpl: Parent {

Tests.playground:4:9: note: candidate has non-matching type ‘ChildImpl’
var child = ChildImpl()

Basically I have two parent-child protocols, and two classes that implement the two protocols. But still, the compiler complains that ChildImpl is not a Child, which is not true.

I can make the errors go away if I use an associated type on Parent

protocol Parent {
    associatedtype ChildType: Child
    var child: ChildType { get }

, however I need to have the protocols available to Objective-C, and also need to be able to reference child as the actual concrete type.

Is there a solution to this that doesn’t involve rewriting the protocols in Objective-C, or doesn’t add duplicate property declarations just to avoid the problem?

Get this bounty!!!

#StackBounty: #ios #swift #cookies #uiwebview iOS How to add cookie to each UIWebView request?

Bounty: 100

I need to open URL with Angular in UIWebView and I need to send cookie with each UIWebView request.

What I tried to do:

I tried to check if request contains cookie. If it does UIWebView performs request, if not I create the same request but with cookie and perform it. To substitute requests I used UIWebViewDelegate‘s method func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool. But it works not as I expected, some requests performs without cookies.

My code:

final class FieldServiceViewController: UIViewController {

    private var webView = UIWebView()
    private var sessionID = String()

    override func viewDidLoad() {

        _ = JSONAPI.getSessionID().subscribe(onNext: { [weak self] sessionID in
            self?.sessionID = sessionID
            let string = "https://someURL"
            let url = URL(string: string)
            let request = URLRequest(url: url!)

    override func viewDidLayoutSubviews() {
        webView.frame = view.bounds

    private func configureUI() {
        webView.delegate = self

    private func cookedRequest(from: URLRequest) -> URLRequest? {

        let cookiesKey = "Cookie"
        let headers = from.allHTTPHeaderFields ?? [:]
        if (headers.contains { $0.0 == cookiesKey }) {
            return nil

        var request = from
        request.cachePolicy = .reloadIgnoringLocalAndRemoteCacheData
        let cookiesToAdd = "SESSIONID=(sessionID)"
        request.addValue(cookiesToAdd, forHTTPHeaderField: cookiesKey)
        return request

    extension FieldServiceViewController: UIWebViewDelegate {

    func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {

        if let cooked = cookedRequest(from: request) {
            return false

        return true

How to add cookie to each UIWebView request?

P.S. I also saved cookie in HTTPCookieStorage, but looks like there is no connection between UIWebView‘s requests and shared storage at all.

Get this bounty!!!