#StackBounty: #ios #objective-c #ipad #nsurlsessiondownloadtask NSURLSession background download not working

Bounty: 50

I am trying to download a number of files using NSURL background session with nsurlsessiontask. Everything works like charm when the app is running in debugging mode (when the device is connected to Xcode), doesn’t work when unplugging device (iPad) from Xcode.

I am using Xcode 7.3.1 with iOS 9.3.5.I have already spent weeks tracing this strange behavior but haven’t got any breakthroughs. May be I missing something to implement background download.
Recently upgraded Xcode to 8.1.2 and iOS to 10.2.1 assuming upgradation might solve the issue but it is not.


Get this bounty!!!

#StackBounty: #ios #objective-c #uiscrollview #uitabbarcontroller Automatically adjust content insets for views with custom a tab bar

Bounty: 50

I created a custom tab bar controller. It works very similar to UITabBarController but with a more advanced layout for the UITabBar.

How do I adjust the bottom content insets for views that appear in my custom tab bar controller? For instance if I show a UITableView in my custom tab bar controller I can manually adjust the content insets like this.

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 49, 0);
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 49, 0);

However the problem gets more complicated if I push another view onto this table view like a collection view. Is there a way to get these views to automatically adjust their content insets like they do in the default UITabBarController implementation?


Get this bounty!!!

#StackBounty: #ios #avplayer #background-process #avplayeritem AVPlayer Not Loading Media In Background

Bounty: 50

When running in the background, my implementation of the AVPlayer is unable to play audio (e.g. podcast) that is downloaded, but is able to play songs that are stored locally. Failure to play in the background is only when the phone is disconnected from my computer. If my phone is direct connected to my computer/debugger, any media that is local or is downloaded plays without a problem. In the foreground, there is also no problem playing either media type.

Here is my implementation:

AVPlayer                    *moviePlayer;               
AVPlayerItem                *playerItem;
NSURL *address = /* the url of either a local song or remote media */

if (moviePlayer != nil) {
    NSLog(@"removing rate, playbackBufferEmpty, playbackLikelyToKeepUp observers before creating new player");
    [moviePlayer removeObserver:self forKeyPath:@"rate"];
    [playerItem removeObserver:self forKeyPath:@"playbackBufferEmpty"];
    [playerItem removeObserver:self forKeyPath:@"playbackLikelyToKeepUp"];
    [playerItem removeObserver:self forKeyPath:@"status"];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemFailedToPlayToEndTimeNotification object:playerItem];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemPlaybackStalledNotification object:playerItem];
    [self setMoviePlayer:nil];  // release and nilify
}

// The following block of code was an experiment to see if starting a background task would resolve the problem. As implemented, this did not help.
if([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive)
{
    NSLog(@"Experiment. Starting background task to keep iOS awake");
    task = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^(void) {
    }];
}

 playerItem = [[AVPlayerItem alloc]initWithURL:address];
 moviePlayer = [[AVPlayer alloc]initWithPlayerItem:playerItem];

 // Add a notification to make sure that the player starts playing. This is handled by observeValueForKeyPath
 [moviePlayer addObserver:self
               forKeyPath:@"rate"
                  options:NSKeyValueObservingOptionNew
                  context:nil];

[playerItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil];
[playerItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
[playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];

 // The following 2 notifications handle the end of play
 [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(moviePlayBackDidFinish:)
                                              name:AVPlayerItemDidPlayToEndTimeNotification
                                            object:playerItem];

 [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(moviePlayBackDidFinish:)
                                              name:AVPlayerItemFailedToPlayToEndTimeNotification
                                            object:playerItem];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackStalled:)
                                             name:AVPlayerItemPlaybackStalledNotification
                                           object:playerItem];

 // Indicate the action the player should take when it finishes playing.
 moviePlayer.actionAtItemEnd = AVPlayerActionAtItemEndPause;

 moviePlayer.automaticallyWaitsToMinimizeStalling = NO;

UPDATE: In the above implementation, I am also showing an experimental attempt to start a background task in hopes of enabling the AVPlayer to play a podcast in the background. This did not help either, but I include it for reference. Not shown, but I also end the background task after the AVPlayerItem playbackLikelyToKeepUp status changes to TRUE.

Then I have the following code to handle the keyPath notifications:

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if ([keyPath isEqualToString:@"rate"]) {
        NSString *debugString = [NSString stringWithFormat: @"In observeValueForKeyPath: rate"];
        DLog(@"%@", debugString);
        debugString = [self appendAvPlayerStatus: debugString];
        [[FileHandler sharedInstance] logDebugString:debugString];
    }
    else if (object == playerItem && [keyPath isEqualToString:@"playbackBufferEmpty"]) {

        NSString *debugString = [NSString stringWithFormat: @"In observeValueForKeyPath: playbackBufferEmpty"];
        DLog(@"%@", debugString);
        debugString = [self appendAvPlayerStatus: debugString];
        [[FileHandler sharedInstance] logDebugString:debugString];
    }
    else if (object == playerItem && [keyPath isEqualToString:@"playbackLikelyToKeepUp"]) {

        NSString *debugString = [NSString stringWithFormat: @"In observeValueForKeyPath: playbackLikelyToKeepUp"];
        DLog(@"%@", debugString);
        debugString = [self appendAvPlayerStatus: debugString];
        [[FileHandler sharedInstance] logDebugString:debugString];
    }

    else if (object == playerItem && [keyPath isEqualToString:@"status"]) {

        NSString *debugString = [NSString stringWithFormat: @"In observeValueForKeyPath: status"];
        DLog(@"%@", debugString);
        debugString = [self appendAvPlayerStatus: debugString];
        [[FileHandler sharedInstance] logDebugString:debugString];
    }
}

And I have the following to handle notificationCenter notifications:

- (void) moviePlayBackDidFinish:(NSNotification*)notification {

    NSLog(@"moviePlaybackDidFinish. Time to stopMoviePlayerWithMusicPlayIndication");
    [self stopMoviePlayer: YES];  // stop the movie player 
}

- (void) moviePlayBackStalled:(NSNotification*)notification {

    NSString *debugString = [NSString stringWithFormat: @"In moviePlayBackStalled. Restarting player"];
    DLog(@"%@", debugString);
    debugString = [self appendAvPlayerStatus: debugString];
    [[FileHandler sharedInstance] logDebugString:debugString];
    [moviePlayer play];
}

By implementing a logging tool to trace execution when disconnected from the computer, here is what I am observing:

When running in the background disconnected from computer, the playerItem is loaded with the url address and the AVPlayer is initialized with the playerItem. This causes the notification observeValueForKeyPath: rate to be posted, but that is the last notification received. Audio does not play. The player just hangs. The output from my log showing various moviePlayer and playerItem flags is as follows:

ready to play movie/podcast/song dedication/Song from url: http://feedproxy.google.com/~r/1019TheMix-EricAndKathy/~5/ZZnF09tuxr0/20170309-1_1718764.mp3
In observeValueForKeyPath: rate - timeCntrlStatus: AVPlayerTimeControlStatusPlaying, itemStatus: AVPlayerItemStatusUnknown, playbackToKeepUp: 0, playbackBufferEmpty: 1, playbackBufferFull: 0, rate: 1.0

However, when running in the background when directly connected to the computer or when running in the foreground, you can see from the log output below that after the url address is loaded and and the AVPlayer is initialized with the playerItem, a series of notifications are posted for keyPath: rate, playbackBufferEmpty, playbackLikelyToKeepUp, and status. Audio then starts playing. The output showing various moviePlayer and playerItem flags is as follows:

ready to play movie/podcast/song dedication/Song from url: http://feedproxy.google.com/~r/1019TheMix-EricAndKathy/~5/d3w52TBzd88/20170306-1-16_1717980.mp3
In observeValueForKeyPath: rate - timeCntrlStatus: AVPlayerTimeControlStatusPlaying, itemStatus: AVPlayerItemStatusUnknown, playbackToKeepUp: 0, playbackBufferEmpty: 1, playbackBufferFull: 0, rate: 1.0
In observeValueForKeyPath: playbackBufferEmpty - timeCntrlStatus: AVPlayerTimeControlStatusPlaying, itemStatus: AVPlayerItemStatusUnknown, playbackToKeepUp: 0, playbackBufferEmpty: 0, playbackBufferFull: 0, rate: 1.0
In observeValueForKeyPath: playbackLikelyToKeepUp - timeCntrlStatus: AVPlayerTimeControlStatusPlaying, itemStatus: AVPlayerItemStatusUnknown, playbackToKeepUp: 0, playbackBufferEmpty: 0, playbackBufferFull: 0, rate: 1.0
In observeValueForKeyPath: status - timeCntrlStatus: AVPlayerTimeControlStatusPlaying, itemStatus: AVPlayerItemStatusReadyToPlay, playbackToKeepUp: 0, playbackBufferEmpty: 0, playbackBufferFull: 0, rate: 1.0
In observeValueForKeyPath: playbackLikelyToKeepUp - timeCntrlStatus: AVPlayerTimeControlStatusPlaying, itemStatus: AVPlayerItemStatusReadyToPlay, playbackToKeepUp: 1, playbackBufferEmpty: 0, playbackBufferFull: 0, rate: 1.0
In observeValueForKeyPath: rate - timeCntrlStatus: AVPlayerTimeControlStatusPlaying, itemStatus: AVPlayerItemStatusReadyToPlay, playbackToKeepUp: 1, playbackBufferEmpty: 0, playbackBufferFull: 0, rate: 1.0

So in summary, you see above that when running in foreground or in background if directly connected to the computer/debugger, the AVPlayer successfully loads the playback buffer and plays the audio. But when running in the background and NOT connected to the computer/debugger, the player does not appear to load the media and just hangs.

In all of the cases, the AVPlayerItemPlaybackStalledNotification is never received.

Sorry for the long explanation. Can anyone see what might be causing the player to hang in the background when not connected to the computer?


Get this bounty!!!

#StackBounty: #ios #swift #realm Add a non realm object as ignored property to realm object in swift?

Bounty: 50

I am trying to add a non-realm class object to realm object something like this.

class TrainTripItinerary: Object {
    dynamic var  departStationName: String?
    dynamic var  departStationCode: String?
    var runningStatus: TrainRunningStatus?

    override static func ignoredProperties() -> [String] {
        return ["runningStatus"]
    }

}

While TrainRunningStatus is not a realm class.

class TrainRunningStatus {
    var trainDataFound: String?
    var startDate: String?
    var startDayDiff: String?
}

I am not able to update runningstatus property now. Anyone know how it works? I fetch separately runnningstatus and assign it to the realm object later but it stays nil even after the assignment.

eg.

let runningStatus = TrainRunningStatus()
trainTripItinerary.runningStatus = runningStatus

This line is not working, trainTripItinerary runningStatus property is not set properly its always nil.


Get this bounty!!!

#StackBounty: #ios #xcode #osx #sdk #twitter-fabric How to create a Fabric (Crashlytics) like iOS SDK installer?

Bounty: 50

I’m working on an iOS SDK that would be installed into 3rd party developers apps. Fabric.io (former Crashlytics) has a great OS-X installer which makes many checkups with Xcode etc. Is there an open source project or example for how to make such a great SDK installer?

Any pointer could help!


Get this bounty!!!

#StackBounty: #ios #objective-c #webkit #sfsafariviewcontroller Could not signal service com.apple.WebKit.WebContent

Bounty: 100

I use the Shopify Mobile Buy SDK for iOS and I can’t get a callback from their payment web view. For some reason the warnings:

2016-11-25 21:17:25.945267 Drool[3328:799969] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service

2016-11-25 21:17:25.977316 Drool[3328:799969] Could not signal service com.apple.WebKit.Networking: 113: Could not find specified service

2016-11-25 21:17:26.105947 Drool[3328:799969] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction

keep showing up and I have no idea why this is happening and if this is the cause of this problem, do any of you know what this is?


Get this bounty!!!

#StackBounty: #ios #json #swift3 #realm #objectmapper Compound key issue Realm Swift

Bounty: 50

I am trying to store json object to realm object using Objectmapper after I receive response from Alamofire. Below is the code I have written:

  func getTodayData() {

    Alamofire.request("https://myapipoint.json").responseJSON{ (response) in

        guard response.result.isSuccess, let value = response.result.value else {
            return
        }
        let json = JSON(value)


        guard let realm = try? Realm() else {
            return
        }

        realm.beginWrite()

        for (_, value): (String, JSON) in json {

            let tpTodayOb = Mapper<TPToday>().map(JSONObject: value.dictionaryObject)

            realm.add(tpTodayOb!, update: true)
        }

        do {
            try realm.commitWrite()
        }
        catch {
            print("Error")
        }
    }
}

I am able to map json data from my server. However, there is an issue with my compound key. The three variables are not unique, but their combination is unique, so I had to use compoundKey as my primary key. I am building primaryKey from compoundKey as follows:

public dynamic var compoundKey: String = "0-"

public override static func primaryKey() -> String? {
   // compoundKey = self.compoundKeyValue()
    return "compoundKey"
}

private func compoundKeyValue() -> String {

    return "(yearNp)-(mahina)-(gate)"
}

This is where I have initialized my three variables.

func setCompoundID(yearNp: Int, mahina: String, gate: Int) {
    self.yearNp = yearNp
    self.mahina = mahina
    self.gate = gate
    compoundKey = compoundKeyValue()
}

And the definition of compoundKey as per Github issues is here. I have 31 dictionaries to be stored in my database, but I am only able to store the last dictionary. I’m sure that this is a compound key issue as this codebase is able to store data in another table which has unique field as primary keys, which is not the case in this database table. Have I declared my compoundKey wrong?


Get this bounty!!!

#StackBounty: #ios #objective-c #mapbox Add blur effect on a Mapbox

Bounty: 100

I want to add blur effect in mapbox.when first time load map that time only display current location in map other map is blue.see screenshot

enter image description here

when i move the userlocation to another location than other location is clear on the map.also display annotation in specific location
see screenshot

enter image description here

help me how can implement this


Get this bounty!!!

#StackBounty: #ios #uiscrollview I want to make effect simliar to resizing top view on contacts app?

Bounty: 50

Native contacts app has interesting effect – when user tries to scroll, the scroll view pushes the top view with avatar and only when top view is in “small mode” it is scrolled up.

enter image description here

enter image description here

I was able to resize view on scrolling, via didScroll method. But problem is, content offset is also changing while i push the top vied. In native contacts, content offset changes only when top view is in “small mode”

Any suggestions, how did they made this?


Get this bounty!!!

#StackBounty: #java #android #libgdx #ios Libgdx: Aligning buttons inside dialog

Bounty: 50

I have the following dialog, semi circle shape. I want to position buttons in it.

enter image description here

        dialog.button(closeButton, false);
        dialog.getContentTable().add(buttonS);
        dialog.getContentTable().add(button);
        dialog.getContentTable().add(hwTo);

The only way I am able to move a button is by using for a example

    dialog.getContentTable().add(hwTo).pad(300);

But I don’t want to pad anything, since it affects other buttons, I tried align, button.setPosition and whatnot, nothing works.

I was told to remove the table and ise Custom WidgetGroup.


Get this bounty!!!