Affichage des articles dont le libellé est Active questions tagged ios - Stack Overflow. Afficher tous les articles
Affichage des articles dont le libellé est Active questions tagged ios - Stack Overflow. Afficher tous les articles

mardi 4 août 2015

Anyone else's Xcode 6.4 crashing after El Capitan beta 6?

I updated my computer to the latest beta that was released to developers last night and the same project that was compiling fine yesterday night now fails due to a supposed .xib/.storyboard error.

I have tried cleaning the project, downloading a previous version off of github, etc.. and yet the project still gives me the following error. "Failed to communicate with Interface Builder" as well as Command /Applications/http://ift.tt/1cExCL8 failed with exit code 255. Literally nothing was changed with the .storyboard file or anything remotely related to it.

What's more is that trying to open any .xib/.storyboard file (even the launch screen xib which I haven't touched leads to Xcode crashing which leads me to think this has nothing to do with me.)

Anyone else experiencing this? Any advice or temporary fixes?

Update: Trying to run anything on the simulator causes it to crash continuously or hang with the following error message: "Springboard quit unexpectedly"

Update 2: Playgrounds are unusable but do not crash. Also, these lads seem to be in the same boat as we are. http://ift.tt/1IE4Wxs

This is why we can't have nice things, Apple.



via Chebli Mohamed

AFNetworking caching using ETag

I have problem implementing caching using AFNetworking and ETag values. My server returns Cache-Control and ETag headers values for every request. But if I make a second request for the same resource AFNetworking won't add ETag. Should I manually save etag for each response I got and append it to next requests?

In app delegate I have set cache object:

 NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:20 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil];
 [NSURLCache setSharedURLCache:URLCache];

Also, I'm using default cache policy of AFHTTPRequestSerializer.

Any ideas what is the problem? Maybe I don't understand the idea of http caching. As far as I know it should be transparent, and all I have to do is to attach ETag and Cache-Control headers for every response.



via Chebli Mohamed

In app purchase not working after publishing iOS app to App Store

During development I've created test accounts which are able to obtain the price of the in app purchase as well as actually purchasing it without an issue. However after publishing the iOS app to App Store, the version of the app in App store can't even retrieve price of the product, and nothing shows up when I press the button to send the purchase request.

Uninstalling the app and redeploy the development version to the same device got it to work again.

What could be the problem? Is there a way to debug or see logs on the app store downloaded version? (iOS noob here)

Thanks!



via Chebli Mohamed

Auto-layout issue on scroll

I have .xib which has some auto-layout like so (might need to click to zoom): enter image description here

Nothing special, I have 13px spacing with the border of the superview. This xib is then loaded in the code into a tableViewCell.

I'm also setting the height in the viewDidLoad of the table like so:

[self.tableView setEstimatedRowHeight:40];
[self.tableView setRowHeight:UITableViewAutomaticDimension];

Now the fun begins. The auto-layout works when it wants to, and sometimes I scroll a cell out of view, bring it back and it's not the same size. See image below: enter image description here

Any ideas on what I am doing wrong?

PS: Not in the screengrab here, but I do have some cells with a lot of text that look like the same height of the big cell on left.



via Chebli Mohamed

Annotation pins and detail view from sqlite in Xcode

I've been looking around the internet to find a tutorial or something to explain this:
I need to show some pins on a map. I need to get them from a sqlite database (table with POI's name, lat, lon, and some text). They have to show annotations callouts with title and subtitle and open their detail views. All that with Xcode and Objective-C. How can I do that? Can anybody help and write the code?



via Chebli Mohamed

iOS autolayout issue

i am using xcode 6.4. i have a view controller named "sample".The view controller contain a scroll view.The scrollview contain another view(container view).The width of container view is thrice of the width of scrollview.when the scroll view is swiping right(or left) it must show the 3 parts of the container view.I did it using paging enabled property of UIscrollview(without auto-layout).But when using auto-layout i cant find a solution.Can anybody tell me a solution for this???please explain constraints for scroll view and container view.Can anybody upload a demo???



via Chebli Mohamed

Progress View and sound with Swift [on hold]

I have a mp3 file in the Supporting Files folder. I can make it play and stop. I put a Progress View from the Object Library to the Main.storyboard, but how to make the Progress View show the progress of the sound when the sound plays?

I would much appreciate if someone could introduce me to the more basics. (I am very new, any simple explanation will help)

var sound1 = AVAudioPlayer()
@IBOutlet var progress: UIView!

@IBAction func play(sender: AnyObject) {
    sound1.play()

}



via Chebli Mohamed

Cannot unpause game when bringing app back to Foreground

My SpriteKit game is automatically paused when the app goes into the background. I'm trying to un-pause the game in the appropriate application events, to no avail. I'm manually un-pausing the two SKViews and the game Scene that constitute the app. From inside the AppDelegate file:

func applicationWillEnterForeground(application: UIApplication) {

    if let vw = self.window?.rootViewController {
        let gc = vw as! GameViewController
        let parView = gc.view as! SKView
        parView.paused = false
        gc.gameView.paused=false
        gc.gameScene.paused=false
        println("paused = \(gc.gameScene.paused)")

    }

}

func applicationDidBecomeActive(application: UIApplication) {

    if let vw = self.window?.rootViewController {
        let gc = vw as! GameViewController
        let parView = gc.view as! SKView
        parView.paused = false

        gc.gameView.paused=false
        gc.gameScene.paused=false
        println("paused = \(gc.gameScene.paused)")

    }

}

At the end I print the pause state. If I hit the device's Home key and then return to the app, it prints false as desired. However, somewhere (not by my code) this is being immediately set back to true, and the game remains paused.



via Chebli Mohamed

Swift AVPlayer has no done button

Using iOS 8.4, I have created an AVPlayerViewController with and AVPlayer. The video controls appear as expected and the video plays, but there is no "Done" button and xCode crashes whenever I try to lay one on the ViewController at the top of the view. An example I saw: Video Playback clearly shows a "Done" button on the upper left of the screen.

Do AVPlayerViewController and AVPlayer support a "Done" button? Is it possible to add one?



via Chebli Mohamed

what is typedef long dispatch_once_t in objective c [duplicate]

This question already has an answer here:

i was going through this tutorial, and i noticed they used:

typedef long dispatch_once_t

yet they did not explain what it does. Furthermore, I have no idea what does "typedef long" mean ? i tried searching through references but didnt find an answer. Can you provide an example of how typedef long works ?



via Chebli Mohamed

How to know which SKSpriteNode is affected by collision detection in Swift?

Situation: I have two or more ships on my iOS screen. Both have different attributes like name, size, hitpoints and score points. They are displayed as SKSpriteNodes and each one has added a physicsBody.

At the moment those extra attributes are variables of an extended SKSpriteNode class.

import SpriteKit    
class ship: SKSpriteNode {
            var hitpoints: Int = nil?
            var score: Int = nil?

        func createPhysicsBody(){
            self.physicsBody = SKPhysicsBody(circleOfRadius: self.size.width / 2)
            self.physicsBody?.dynamic = true
            ...
        }
    }

In this 'game' you can shoot at those ships and as soon as a bullet hits a ship, you get points. 'Hits a ship' is detected by collision.

func didBeginContact(contact: SKPhysicsContact){    
    switch(contact.bodyA.categoryBitMask + contact.bodyB.categoryBitMask){
        case shipCategory + bulletCategory:
            contactShipBullet(contact.bodyA, bodyB: contact.bodyB)
            break;
        default:
            break;
    }
}

Problem: Collision detection just returns a physicsBody and I do not know how to get my extended SKSpriteNode class just by this physicsBody.

Thoughts: Is it a correct way to extend SKSpriteNode to get my objects like a ship to life? When I add a ship to my screen it looks like:

var ship = Ship(ship(hitpoints: 1, score: 100), position: <CGPosition>)
self.addChild(ship)

Or is this just a wrong approach and there is a much better way to find out which object with stats so and so is hit by a bullet thru collision detection?

This question is similar to my other question - I just want ask this in broader sense.



via Chebli Mohamed

How can I create a cv:Mat from UIImage/NSData?

I'm working on image recognition for our company app (iOS).

Initially what I wanted to do is: to make a photo of some digits number and try to use recognition library tesseract. The problem is: the tesseract doesn't work good enough for me. So I decided to use image recognition instead of text recognition library.

I've made pictures of numbers from 0 to 9 with the font I need with the background I need. Next I take a photo of a number (which consists of several digits). Then I wanna compare the digits to the pictures I've made. The algorithm I've found on the internet. The problem is: I have to create a cv::Mat object for the photo, which I've taken in order to make a comparison. I'm working with iOS (Objective-C), so the image object is UIImage. How can I convert the UIImage to the cv::Mat object ?

I need somehow to decode the NSData object to the cv::Mat (the NSData object I can get from the following code, where testedImage is the UIImage*)

NSData *testedImageData = UIImagePNGRepresentation(testedImage);

The only way I can do it now is to save the picture on the file system and then get it's path and create a cv::Mat object, but it's not a good idea ...



via Chebli Mohamed

JSON parsing using [NSJSONSerialization JSONObjectWithData:dataJson options:0 error:&error] thowing nil

error = Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Garbage at end.) UserInfo=0x7fa4e25da7c0 {NSDebugDescription=Garbage at end.}

If changing NSData to NSString , response is getting but using

id jsonData = [NSJSONSerialization JSONObjectWithData:dataJson options:0 error:&error]

showing above error, and response nil.



via Chebli Mohamed

View is presented modally instead of Show

So I have a TableViewController. When a cell is tapped, a showEpisodes segue is called. This segue is set as Show and pointed to a Navigation Controller, like this:

Segue

The problem is that my view shows modally, i.e it doesn't have a navigationcontroller.

Here is the code I use in Main Table View Controller

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let cell = tableView.cellForRowAtIndexPath(indexPath)
    self.performSegueWithIdentifier("showEpisodes", sender: cell?.textLabel?.text)

}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showEpisodes" {
        let viewController = segue.destinationViewController as! UINavigationController
        let vc = viewController.topViewController as! EpisodesTableViewCOntroller
        let indexPath: NSIndexPath = self.tableView.indexPathForSelectedRow!
        let object: PFObject = self.objectAtIndexPath(indexPath)!
        vc.podcast = object
       // self.navigationController!.pushViewController(vc, animated: true)
    }

}

If I uncomment the self.navigationController!.pushViewController(vc, animated: true) part, the view will get pushed fine but as soon as it is loaded, a black window is modally presented over it. I've checked the UI Hierarchy in the debugger without success. Any ideas please?



via Chebli Mohamed

In Swift, how can I get an NSDate from a dispatch_time_t?

"Walltime" is a little-known time format used by Grand Central Dispatch. Apple talks about it here:

http://ift.tt/1HnSNLW

There are some things it's really handy for, though, but it's a sticky wicket. It's hard to make it play nice with other time formats, which is what my question's about.

I can make a walltime by turning an NSDate into a timespec, and then using with dispatch_walltime:

 let now = NSDate().timeIntervalSince1970
 let nowWholeSecsFloor = floor(now)
 let nowNanosOnly = now - nowWholeSecsFloor
 let nowNanosFloor = floor(nowNanosOnly * Double(NSEC_PER_SEC))
 var thisStruct = timespec(tv_sec: Int(nowWholeSecsFloor),
 tv_nsec: Int(nowNanosFloor))
 let wallTime = dispatch_walltime(& thisStruct, 0)

But lord love a duck, I can't figure out how to get it back into an NSDate. Here's my try:

public func toNSDate(wallTime: dispatch_time_t)->NSDate {
    let wallTimeAsSeconds = Double(wallTime) / Double(NSEC_PER_SEC)
    let date = NSDate(timeIntervalSince1970: wallTimeAsSeconds)
    return date
}

The resulting NSDate is not just off, but somewhat hilariously off, like five hundred years or something. As Martin R pointed out, the problem is that dispatch_time_t is an opaque value, with an undocumented representation of time.

Does anyone know how to do this?

EDIT: if the process of creating the walltime is confusing, this is basically what's going on:

NSDate defines time with a Double, and everything after the decimal point is the nanoseconds. dispatch_time, which can create a walltime, defines time with UInt64, so you have to convert between Double and UInt64 to use it. To do that conversion you need to use a timespec, which takes seconds and nanoseconds as separate arguments, each of which must be Int.

A whole lotta convertin' going on!



via Chebli Mohamed

Obj-c method with nullable return value not properly converting to swift

I have a problem where the following OBJ-C method will not translate to Swift with optional return value:

- (nullable id)executeRequest:(ServerRequest *)request returningResponse:(__nullable NSURLResponse **__nullable)responseRef errorRef:(NSError **)errorRef

When trying to override that method in a swift class it translates to this:

override func executeRequest(request: ServerRequest, returningResponse responseRef: AutoreleasingUnsafeMutablePointer<NSURLResponse?>) throws -> AnyObject

Note that the return value is AnyObject instead of AnyObject?

What am I doing wrong here? I'm using X-Code 7 Beta 3



via Chebli Mohamed

GCM extension for AIR on ios?

Is the an extension for using GCM on AIR project in ios?

I know GCM works on ios native http://ift.tt/1f8Y8Rq

but I need it to work on Adobe Air



via Chebli Mohamed

How to plot the route in Ios when user walikng or driving along the road using Google Maps SDK

Hi i am beginner for using Google maps in Ios and i my project i am trying to plot the route when user walking or driving along the road but here current location is getting but route is not plotting when user walking laong road if any body know about this please help me

My code below:-

#import "ViewController.h"

@interface ViewController ()
{
    GMSMapView *_mapView;
    NSMutableArray *_coordinates;
    LRouteController *_routeController;
    GMSPolyline *_polyline;
    GMSMarker *_markerStart;
    GMSMarker *_markerFinish;
    CLLocationManager *locationManager_;
}

@end

@implementation ViewController

- (void)viewDidLoad{

    [super viewDidLoad];

    _markerStart = [[GMSMarker alloc]init];
    _markerFinish = [[GMSMarker alloc]init];

    _coordinates = [[NSMutableArray alloc]init];

    locationManager_ = [[CLLocationManager alloc] init];
    locationManager_.delegate = self;
    [locationManager_ setDistanceFilter:10.0f];
    locationManager_.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager_ requestAlwaysAuthorization];
    [locationManager_ startUpdatingLocation];
 }

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{

    _polyline.map = nil;
    _markerStart.map = nil;
    _markerFinish.map = nil;

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:newLocation.coordinate.latitude
                                                            longitude:newLocation.coordinate.longitude
                                                                 zoom:16];

    _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    _mapView.myLocationEnabled = YES;
    _mapView.settings.myLocationButton = YES;
    self.view = _mapView;

    _markerStart.position = CLLocationCoordinate2DMake(newLocation.coordinate.latitude, newLocation.coordinate.longitude);
    _markerStart.title = @"CurrentLocation";
    _markerStart.snippet = @"Hello";
    _markerStart.map = _mapView;

    _markerFinish.title = @"Finish";
    _markerFinish.snippet = @"End";
    _markerFinish.map = _mapView;

    NSLog(@"didUpdateToLocation: %@", newLocation);
    NSLog(@"new location %f",newLocation.coordinate.latitude);
    NSLog(@"new location %f",newLocation.coordinate.longitude);

    [_coordinates addObject:[[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude]];

    NSLog(@"array list %lu",(unsigned long)_coordinates.count);

    if ([_coordinates count] > 1)

    {
        NSLog(@"1");

        [_routeController getPolylineWithLocations:_coordinates travelMode:TravelModeDriving andCompletitionBlock:^(GMSPolyline *polyline, NSError *error) {

            if (error)
            {
                NSLog(@"%@", error);
            }

            else if (!polyline)
            {
                NSLog(@"No route");
                [_coordinates removeAllObjects];
            }

            else
            {
                _markerStart.position = [[_coordinates objectAtIndex:0] coordinate];
                _markerStart.map = _mapView;
                _markerFinish.position = [[_coordinates lastObject] coordinate];
                _markerFinish.map = _mapView;

                _polyline = polyline;
                _polyline.strokeWidth = 3;
                _polyline.strokeColor = [UIColor redColor];
                _polyline.map = _mapView;
            }
        }];
    }
}

@end

But route is not plotting please help me some one



via Chebli Mohamed

Deleting all rows from UITableView

I keep running into an assertion failure but I am not sure how to resolve.

Initially I did a proof of concept app to understand how this functions and had this code in it:

if (self.arrNonATIResults.count > 0) {
        NSMutableArray* arrIndexPaths = [NSMutableArray array];
        for(int i=0; i<[self.arrNonATIResults count]; i++) {
            NSIndexPath *anIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
            [arrIndexPaths addObject:anIndexPath];
        }

        [self.accountTable beginUpdates];
        [self.accountTable deleteRowsAtIndexPaths:arrIndexPaths  withRowAnimation:UITableViewRowAnimationTop];
        self.arrNonATIResults = [NSMutableArray array];
        [self.accountTable endUpdates];
    }

It worked fine. Moving that code into my app I ran into this assertion failure:

Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (0 inserted, 2 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).

Here's where I am getting confused, self.arrNonATIResults (the table datasource) contains two objects (it's hardcoded) - so the table has only two rows. Where is the 3rd row in the error message coming from? I did read that if you remove all rows then you also have to remove the section as well. Is that the third item in the error message?

So I rewrote my initial code but this still shouldn't work because the arrIndexPath array is only going to include 2 NSIndexPaths. Can anyone point me in the right direction as to what I am doing wrong?

   - (void) clearNonATITable {

        if (self.arrNonATIResults.count > 0) {

            NSMutableArray* arrIndexPaths = [NSMutableArray array];
            for(int i=0; i<[self.arrNonATIResults count]; i++) {
                NSIndexPath *anIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
                [arrIndexPaths addObject:anIndexPath];
            }


            [self.accountTable beginUpdates];

            for (int i=0; i<arrIndexPaths.count; i++) {

                NSIndexPath* thisIndexPath = [arrIndexPaths objectAtIndex:i];

                if (self.arrNonATIResults.count > 0) {
                    [self.accountTable deleteRowsAtIndexPaths:[NSArray arrayWithObjects:thisIndexPath, nil] withRowAnimation:UITableViewRowAnimationFade];
                    [self.arrNonATIResults removeObjectAtIndex:0];
                } else {
                    NSIndexSet* setIndexSections = [[NSIndexSet alloc] initWithIndex:thisIndexPath];
                    [self.accountTable deleteSections:setIndexSections withRowAnimation:UITableViewRowAnimationFade];
                }
            }

            [self.accountTable endUpdates];

        }
    }




via Chebli Mohamed

Is it possible to add view behind navigation bar in UITableViewController

I wonder if its possible to add a view under the navigation bar in a UITableViewController?

What I would like to do is to add a view under the navigation bar in my UITableViewController so that I can add a search input / filter button to that view. But I want the view to have a fixed position under the navigation bar so that I can hide the navigationbar+view when swiping.

Right now storyboard only lets me add a view in the UITableViewController. And the new view is also swipeable. And the loading indicator shows up above the view when you swipe down.

enter image description here



via Chebli Mohamed