Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS module #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ build.log
.DS_Store
android/build.properties
parse.jar
cloudcode/config/local.json
cloudcode/config/local.json
iphone/build
45 changes: 11 additions & 34 deletions android/src/eu/rebelcorp/parse/ParseModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public void onStart(Activity activity)
{
super.onStart(activity);
setState(STATE_RUNNING);

// Track app opens
ParseAnalytics.trackAppOpened(TiApplication.getAppRootOrCurrentActivity().getIntent());
ParseInstallation.getCurrentInstallation().put("androidId", getAndroidId());
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e != null) {
Log.e(TAG, "Installation initialization failed: " + e.getMessage());
}
}
});
}

public void onResume(Activity activity)
Expand Down Expand Up @@ -116,40 +127,6 @@ public static ParseModule getInstance() {
}

// Methods
@Kroll.method
public void start()
{
setState(STATE_RUNNING);
// Track Push opens
ParseAnalytics.trackAppOpened(TiApplication.getAppRootOrCurrentActivity().getIntent());
ParseInstallation.getCurrentInstallation().put("androidId", getAndroidId());
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e != null) {
Log.e(TAG, "Installation initialization failed: " + e.getMessage());
}
}
});
}

@Kroll.method
public void enablePush() {
// Deprecated. Now happens automatically
}

@Kroll.method
public void authenticate(@Kroll.argument String sessionToken) {
ParseUser.becomeInBackground(sessionToken, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
// Hooray! The user is logged in.
} else {
// Signup failed. Look at the ParseException to see what happened.
}
}
});
}

@Kroll.method
public void subscribeChannel(@Kroll.argument String channel) {
ParsePush.subscribeInBackground(channel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,15 @@
#import "TiModule.h"
#import "RebelParseUserProxy.h"

#import <ParseFacebookUtils/PFFacebookUtils.h>
#import <FacebookSDK/FacebookSDK.h>
#import <Parse/Parse.h>

@interface RebelParseModule : TiModule {
@interface EuRebelcorpParseModule : TiModule {
@private
RebelParseUserProxy* currentUser;
}



-(void)signup:(id)args;
-(void)login:(id)args;
-(void)logout;
-(void)resetPassword:(id)args;

-(void)loginWithFacebook:(id)args;
-(void)callFunction:(id)args;

@end
196 changes: 196 additions & 0 deletions iphone/Classes/EuRebelcorpParseModule.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
/**
* Parse
*
* Created by Timan Rebel
* Copyright (c) 2014 Your Company. All rights reserved.
*/

#import "EuRebelcorpParseModule.h"
#import "TiBase.h"
#import "TiHost.h"
#import "TiUtils.h"
#import "TiApp.h"

@implementation EuRebelcorpParseModule

#pragma mark Internal

// this is generated for your module, please do not change it
-(id)moduleGUID
{
return @"e700fd13-7783-4f1c-9201-1442922524fc";
}

// this is generated for your module, please do not change it
-(NSString*)moduleId
{
return @"eu.rebelcorp.parse";
}

#pragma mark Lifecycle

-(void)load
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationOpened:) name:@"UIApplicationDidFinishLaunchingNotification" object:nil];
}

-(void)startup
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *launchOptions = [[TiApp app] launchOptions];

NSString *applicationId = [[TiApp tiAppProperties] objectForKey:@"Parse_AppId"];
NSString *clientKey = [[TiApp tiAppProperties] objectForKey:@"Parse_ClientKey"];

NSLog(@"Initializing with: %@, %@", applicationId, clientKey);

[Parse setApplicationId:applicationId
clientKey:clientKey];

[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];

// this method is called when the module is first loaded
// you *must* call the superclass
[super startup];
}

#pragma mark Cleanup

-(void)dealloc
{
// release any resources that have been retained by the module
[super dealloc];
}

#pragma mark Internal Memory Management

-(void)didReceiveMemoryWarning:(NSNotification*)notification
{
// optionally release any resources that can be dynamically
// reloaded once memory is available - such as caches
[super didReceiveMemoryWarning:notification];
}


#pragma User

-(void)login:(id)args
{
NSString *username = [args objectAtIndex:0];
NSString *password = [args objectAtIndex:1];

[PFUser logInWithUsernameInBackground:username password:password block:^(PFUser *user, NSError *error) {
if (user) {
// Do stuff after successful login.
} else {
// The login failed. Check error to see why.
}
}];
}

-(void)logout
{
[PFUser logOut];
}

-(void)resetPassword:(id)email
{
ENSURE_SINGLE_ARG(email, NSString);

[PFUser requestPasswordResetForEmailInBackground:email];
}

-(id)currentUser
{
if(currentUser == nil && [PFUser currentUser] != nil) {
currentUser = [[RebelParseUserProxy alloc]init];
currentUser.pfObject = [[PFUser currentUser] retain];
}

return currentUser;
}

#pragma Push Notifications
-(void)notificationOpened:(NSNotification *)userInfo {
NSLog(@"Notification opened");
[PFAnalytics trackAppOpenedWithRemoteNotificationPayload:[userInfo userInfo]];
}

-(void)registerDeviceToken:(id)deviceToken
{
ENSURE_SINGLE_ARG(deviceToken, NSString);

// Store the deviceToken in the current Installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:[deviceToken dataUsingEncoding:NSUTF8StringEncoding]];
[currentInstallation saveInBackground];
}

-(void)registerForPush:(id)args {
ENSURE_ARG_COUNT(args, 3);

NSString *deviceToken = [args objectAtIndex:0];
NSString *channel = [args objectAtIndex:1];
KrollCallback *callback = [args objectAtIndex:2];

NSLog(@"Register for push notification on channel %@ with device token %@", channel, deviceToken);

// Store the deviceToken in the current Installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceToken:deviceToken];
[currentInstallation addUniqueObject:channel forKey:@"channels"];

[currentInstallation saveInBackgroundWithBlock:^(BOOL success, NSError *error) {
if (callback) {
NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:success], @"success", [error userInfo], @"error", nil];
[self _fireEventToListener:@"completed" withObject:result listener:callback thisObject:nil];
}
}];
}

-(void)subscribeChannel:(id)channel
{
ENSURE_SINGLE_ARG(channel, NSString);

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation addUniqueObject:channel forKey:@"channels"];
[currentInstallation saveInBackground];
}

-(void)unsubscribeChannel:(id)channel
{
ENSURE_SINGLE_ARG(channel, NSString);

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation removeObject:channel forKey:@"channels"];
[currentInstallation saveInBackground];
}

-(void)putValue:(id)args
{
ENSURE_ARG_COUNT(args, 2);
ENSURE_TYPE([args objectAtIndex:0], NSString);
ENSURE_TYPE([args objectAtIndex:1], NSObject);

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation addObject:[args objectAtIndex:1] forKey:[args objectAtIndex:0]];
[currentInstallation saveInBackground];
}

#pragma Property getter
-(NSString *)currentInstallationId
{
return [PFInstallation currentInstallation].installationId;
}

-(NSString *)objectId
{
return [PFInstallation currentInstallation].objectId;
}

-(NSArray *)channels:(id)args
{
return [PFInstallation currentInstallation].channels;
}

@end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* This is a generated file. Do not edit or your changes will be lost
*/
#import "RebelParseModuleAssets.h"
#import "EuRebelcorpParseModuleAssets.h"

extern NSData* filterDataInRange(NSData* thedata, NSRange range);

Expand Down
Loading