Skip to content

Instantly share code, notes, and snippets.

View funkyboy's full-sized avatar

Cesare funkyboy

View GitHub Profile
@funkyboy
funkyboy / screenBrightness
Last active August 29, 2015 13:56
To detect when screen brightness changes in iOS
ASCScreenBrightnessDetector *brightnessDetector =
[ASCScreenBrightnessDetector new];
brightnessDetector.delegate = self;
- (void)screenBrightnessDidChange:(CGFloat)brightness {
NSLog(@"Brightness is: %f", brightness);
}
@funkyboy
funkyboy / importing BaasBox
Created March 17, 2014 20:11
Importing BaasBox in the .pch file
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "BAAClient.h"
#endif
@funkyboy
funkyboy / gist:9607776
Created March 17, 2014 20:33
Initializing BaasBox
[BaasBox setBaseURL:@"http://localhost:9000"
appCode:@"1234567890"];
@funkyboy
funkyboy / gist:9616544
Last active August 29, 2015 13:57
Creating a user in BaasBox
- (void) createUser {
BAAClient *client = [BAAClient sharedClient];
[client createUserWithUsername:@"cesare"
password:@"password"
completion:^(BOOL success, NSError *error) {
if (success) {
@funkyboy
funkyboy / gist:9616684
Last active August 29, 2015 13:57
Upload a file in BaasBox
- (void) uploadFile {
NSURL *imgPath = [[NSBundle mainBundle] URLForResource:@"baasbox" withExtension:@"png"];
NSString* stringPath = [imgPath absoluteString];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:stringPath]];
BAAFile *myLocalFile = [[BAAFile alloc] initWithData:data];
myLocalFile.contentType = @"image/png";
[myLocalFile uploadFileWithPermissions:nil
completion:^(BAAFile *file, NSError *error) {
@funkyboy
funkyboy / gist:9914064
Created April 1, 2014 13:33
Importing BaasBox
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "BAAClient.h" // <­ added import statement
@interface SMPost : BAAObject
...;
@end
- (instancetype) initWithDictionary:(NSDictionary *)dictionary {
self = [super initWithDictionary:dictionary];
if (self) {
_postTitle = dictionary[@"postTitle"];
_postBody = dictionary[@"postBody"];
}
- (NSString *)collectionName {
return @"document/memos";
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
BAAClient *client = [BAAClient sharedClient];
if (client.isAuthenticated) {
NSLog(@"Logged in");