A simple #Watchkit app in #ObjectiveC
Yes, I just got an apple watch, and the first thing I want to do with it, is to learn to program on it. so, apart from a simple “Hello World” app. I wanted to create a very simple companion app for a bitcoin app (https://itunes.apple.com/gb/app/get-bitcoin/id1072062149?mt=8) – which just looks up the BTC / USD exchange rate and shows it on the watch.
So, here’s the code;
@interface InterfaceController()
@property (unsafe_unretained, nonatomic) IBOutlet WKInterfaceLabel *lblHello;
@end
@implementation InterfaceController
– (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
// Configure interface objects here.
[self.lblHello setText:@”Loading…”];
// make request to https://blockchain.info/tobtc?currency=USD&value=1
NSURL *url = [NSURL URLWithString:@”https://blockchain.info/tobtc?currency=USD&value=1″];
NSError* error;
NSString *content = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error];
// Check for network errors
if (error)
{
[self.lblHello setText:@”Network error”];
return;
}
// Get reciprocal
float fRate = [content floatValue];
float fReciprocal = 1 / fRate;
NSString *str = [NSString stringWithFormat:@”$%.2lf”, fReciprocal];
[self.lblHello setText:str];
}
-
February 7, 2017 at 9:04 amFirst Apple #Watch #App now live | Network Programming in .NET