mardi 5 mai 2015

How to disable Apple Watch auto sleep in an app?

I have a written an app for Apple Watch and I don't want the watch to go to sleep while my app is running. How can I disable the idle timer on watch?

How to edit one complex object in multiple screens in Android?

I'm trying to figure out best/correct way to edit one complex object on multiple screens in Android. I have Event which has a collection of Invites. Event is edited on one screen and Invites list is composed on another. User first edits event data then goes to address book like screen to add/remove invites then goes back to event screen and send all changes to server.

I'm using Xamarin and want to have same business logic code on both iOS and Android. On iOS I have Event object with InvitesList inside it. I pass InvitesList to InvitesController and it edits this list and this is basically it. Everything works as intended. Sample code:

public class Event {
  InvitesList Invites { get; private set; }
  public async Task Save() {
    await service.SaveEvent(this);
    await service.SyncContacts(Invites.New, Invites.Removed);
  }
}

My problem is that above scenario does not work with Android if I want to edit InvitesList in a separate activity. InvitesList knows how to load it data from server and it also tracks additions and deletions so Event object could figure out what server API calls it need to do later on. AFAIK my options are

  1. Create InviteListMemento and pass it back and forth between activities. I don't like it because I'll will have to serialize potentially large list of added Contacts or Contact object might be large (for example have images inside or maybe dozen of strings).
  2. Save InvitesList in static variable. This is ugly and I'd like to avoid this solution.

I don't like any of above solutions. Can anyone suggest a solution which would allow me to keep my business objects intact? I'd like to have Event object with InvitesList inside and also to be able to edit InvitesList in separate activity. Ideally I also would like to keep changes required only for Android to a minimum.

Keychain data can't be shared between apps

I've got keychain dumper working fine on an iPad Air. I have a bunch of apps where I am sharing keychain data. This works great. These apps are older and compiled under Xcode 4. I've got a jailbroken iPad and have used Keychain Dumper which sees all these apps data.

I now have a new iOS App (Cordova HTML-based) which I use a different keychain plugin for. It's compiled by xCode 6.

Keychain dumper (with -a) cannot see the data saved by this project, even though it persists and restores correctly. Even when the app is running, I cannot see the keychain data. It also cannot share the keychain data from the other apps even though I use the same bundle seed etc, and follow the same recipe I always did. It's writing in a different location or something.

Have the defaults for saving keychain data changed somehow?

Unable to set velocity of sprites correctly

I am making an asteriods-like app in iOS8. I have code that creates a laser shot and sets its velocity vector according to the facing of the ship. When the ship is oriented upwards on the screen, the code works correctly. When the ship is oriented downwards on the screen the sprite has no, or almost no, velocity along the y-axis. That is, the .dy component of physicsBody.velocity behaves as if it is near zero; the .dx component behaves correctly. LLDB reports the .dy component as what it should be, but the sprite moves incorrectly. Here is the relevant code:

func createLaser()->SKSpriteNode {
    let laserBeam = SKSpriteNode(imageNamed: "laserBeam")
    laserBeam.name = "laserBeam"
    laserBeam.position.x = shipNode.position.x
    laserBeam.position.y = shipNode.position.y
    laserBeam.physicsBody = SKPhysicsBody(circleOfRadius: 10.0)
    laserBeam.physicsBody?.dynamic = true
    laserBeam.physicsBody?.affectedByGravity = false
    laserBeam.zRotation = shipNode.zRotation
    laserBeam.physicsBody?.mass = 1.0
    laserBeam.physicsBody?.velocity.dx = kLaserSpeed * sin(shipNode.zRotation ) * -1 //TODO apply an impulse instead?
    laserBeam.physicsBody?.velocity.dy = kLaserSpeed * cos(shipNode.zRotation) * 1
    println("in create Laser ship rotation = \(shipNode.zRotation), dx = \(laserBeam.physicsBody?.velocity.dx), dy = \(laserBeam.physicsBody?.velocity.dy)")
    return laserBeam
}

Error with Json http request iOS

I am trying to work on Livelink restful services and get data in iOS Application. The documentation link for api is:

http://ift.tt/1OY65sS

Code I am using for getting response data is:

NSDictionary *authDict = [[NSDictionary alloc] initWithObjectsAndKeys:
                              @"XYZ",@"username",
                              @"ABC",@"password",
                              nil];
NSError *error;
NSData *requestData = [NSJSONSerialization dataWithJSONObject:authDict options:0 error:&error];
NSURL *url = [NSURL URLWithString:@"http://ift.tt/1EOCLwR"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];                                              
[request setHTTPMethod:@"POST"]; 
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: requestData];

NSURLResponse *requestResponse;
NSData *requestHandler = [NSURLConnection sendSynchronousRequest:request returningResponse:&requestResponse error:nil];

NSString *requestReply = [[NSString alloc] initWithBytes:[requestHandler bytes] length:[requestHandler length] encoding:NSASCIIStringEncoding]; 

But in request reply I am not getting authentication result.When I log request reply,the log is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://ift.tt/mOIMeg">
<html xmlns="http://ift.tt/lH0Osb">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>500 - Internal server error.</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;} 
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0;color:#CC0000;} 
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} 
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
background-color:#555555;}
#content{margin:0 0 0 2%;position:relative;}
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
-->
</style>
</head>
<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
 <div class="content-container"><fieldset>
  <h2>500 - Internal server error.</h2>
  <h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3>
 </fieldset></div>
</div>
</body>
</html>

Could you please help me to get the Authentication ticket. Thanks in advance.

Feeding dynamic data to UICollectionView within UITableViewCell

Hello friendly swifters.

I am generating a table of cells.
each cell contains 2 labels, 1 button, 1 collectionview
each collectionview will display a collection of images

I can get my dynamic data to update the labels and buttons as needed.

I could use some help getting the collectionview cell to show my images. The collectionview prototype does have an imageview within it, which is linked to my collectionviewcell class.

example of empty collection views:
enter image description here

here's some code:

//My TableView 'cellForRowAtIndexPath

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell:DeckTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell2", forIndexPath: indexPath) as! DeckTableViewCell

    let deck:PFObject = timeLineData.objectAtIndex(indexPath.row) as! PFObject

    let sequenceTemp = deck.objectForKey("Sequence") as! String

    cell.sequenceId.setTitle(deck.objectId, forState: UIControlState.Normal)
    cell.cardCountLabel.text = "\((count(sequenceTemp)/2))"

    var dateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "(MM-dd) hh:mm:ss"
    cell.timeLabel.text = dateFormatter.stringFromDate(deck.updatedAt!)

    return cell
}


let images = ["2C.png", "3C.png", "4C.png", "5C.png", "6C.png", "7C.png", "8C.png", "9C.png", "10C.png", "JC.png", "QC.png", "KC.png", "AC.png"]

//My CollectionView 'cellForItemAtIndexPath

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let cell: TableCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! TableCollectionViewCell

    let image = UIImage(named: images[indexPath.row])

    cell.ImageView.image = image
    cell.ImageView.backgroundColor = UIColor.orangeColor()

    return cell
}

The collectionview cell is not updating, not even to orange.

thanks for your time.

(XCode) Error signal SIGTERM everytime I quit the iOS simulator

Everytime I quit the iOS Simulator using XCode the error "Thread 1: signal SIGTERM" shows up in the AppDelegate.swift file, right in the "class AppDelegate:___{" line. The only thing that shows up in the console is "(llbd)".