Skip to content

Commit

Permalink
Merge pull request #1 from hansemannn/master
Browse files Browse the repository at this point in the history
Adjust SDK reference, add some API's, bump 1.1.0
  • Loading branch information
williamrijksen authored Nov 12, 2016
2 parents 1839ddd + 4943ecb commit ed9d790
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Plafile.yml
build.properties
libs
*/dist/modules
*.xcuserdatad
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ This module gives you the possibility to integrate OneSignal into you're Appcele

1. Integrate the module into the `modules` folder and define them into the `tiapp.xml` file:

```
```xml
<modules>
<module platform="iphone" version="1.0.0">com.williamrijksen.onesignal</module>
<module platform="iphone" version="1.1.0">com.williamrijksen.onesignal</module>
<module platform="android" version="1.0.0">com.williamrijksen.onesignal</module>
</modules>
```
1. Configure your app into the App Settings panel for the right Platform (Android and/or iOS).
1. To use OneSignal on iOS devices, register the OneSignal-appId into `tiapp.xml`:

```
```xml
<property name="OneSignal_AppID" type="string">[App-id]</property>
```
1. To use OneSignal on Android devices, register some meta-data as well:

```
```xml
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data android:name="onesignal_app_id"
Expand All @@ -36,20 +36,38 @@ This module gives you the possibility to integrate OneSignal into you're Appcele
### Usage
1. Register device for Push Notifications

```
```js
// This registers your device automatically into OneSignal
var onesignal = require('com.williamrijksen.onesignal');
```
1. To add the possibility to target people for notifications, send a tag:

```
```js
onesignal.sendTag({ key: 'foo', value: 'bar' });
```
1. Delete tag:

```
```js
onesignal.deleteTag({ key: 'foo' });
```

1. Get tags (iOS-only for now):

```js
onesignal.getTags(function(e) {
if (!e.success) {
Ti.API.error("Error: " + e.error);
return
}

Ti.API.info(e.results);
});
```
1. Set log level (iOS-only for now):

```js
onesignal.setLogLevel({
logLevel: onesignal.LOG_LEVEL_DEBUG,
visualLevel: onesignal.LOG_LEVEL_NONE
});
```
Cheers!
11 changes: 8 additions & 3 deletions iphone/Classes/ComWilliamrijksenOnesignalModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
#import "TiModule.h"
#import <OneSignal/OneSignal.h>

@interface ComWilliamrijksenOnesignalModule : TiModule
{
}
@interface ComWilliamrijksenOnesignalModule : TiModule {}

typedef void(^TagsResultHandler)(NSDictionary*, NSError*);

- (void)sendTag:(id)args;
- (void)deleteTag:(id)args;
- (void)getTags:(id)value;
- (void)setLogLevel:(id)args;

@end
81 changes: 57 additions & 24 deletions iphone/Classes/ComWilliamrijksenOnesignalModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,14 @@ -(NSString*)moduleId

- (void)startup
{
[super startup];
[[TiApp app] setRemoteNotificationDelegate:self];
[super startup];
[[TiApp app] setRemoteNotificationDelegate:self];

NSString *OneSignalAppID = [[TiApp tiAppProperties] objectForKey:@"OneSignal_AppID"];
//Add this line. Replace '5eb5a37e-b458-11e3-ac11-000c2940e62c' with your OneSignal App ID.
[OneSignal initWithLaunchOptions:[[TiApp app] launchOptions] appId:OneSignalAppID];
}

- (void)shutdown:(id)sender
{
[super shutdown:sender];
}

#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 mark Public API's

- (void)sendTag:(id)args
{
Expand All @@ -79,4 +59,57 @@ - (void)deleteTag:(id)args
[OneSignal deleteTag:key];
}

- (void)getTags:(id)value
{
ENSURE_UI_THREAD(getTags, value);
ENSURE_SINGLE_ARG(value, KrollCallback);

// Unifies the results (success) and error blocks to fire a single callback
TagsResultHandler resultsBlock = ^(NSDictionary *results, NSError* error) {
NSMutableDictionary *propertiesDict = [NSMutableDictionary dictionaryWithDictionary:@{
@"success": NUMBOOL(error == nil),
}];

if (!error) {
// Are all keys and values Kroll-save? If not, we need a validation utility
[propertiesDict setObject:results ?: @[] forKey:@"results"];
} else {
[propertiesDict setObject:[error localizedDescription] forKey:@"error"];
[propertiesDict setObject:NUMINTEGER([error code]) forKey:@"code"];
}

NSArray *invocationArray = [[NSArray alloc] initWithObjects:&propertiesDict count:1];
[value call:invocationArray thisObject:self];
[invocationArray release];
};

[OneSignal getTags:^(NSDictionary *results) {
resultsBlock(results, nil);
} onFailure:^(NSError *error) {
resultsBlock(nil, error);
}];
}

- (void)setLogLevel:(id)args
{
ENSURE_UI_THREAD(setLogLevel, args);
ENSURE_SINGLE_ARG(args, NSDictionary);

id logLevel = [args objectForKey:@"logLevel"];
id visualLevel = [args objectForKey:@"visualLevel"];

ENSURE_TYPE(logLevel, NSNumber);
ENSURE_TYPE(visualLevel, NSNumber);

[OneSignal setLogLevel:[TiUtils intValue:logLevel] visualLevel:[TiUtils intValue:visualLevel]];
}

MAKE_SYSTEM_PROP(LOG_LEVEL_NONE, ONE_S_LL_NONE);
MAKE_SYSTEM_PROP(LOG_LEVEL_DEBUG, ONE_S_LL_DEBUG);
MAKE_SYSTEM_PROP(LOG_LEVEL_INFO, ONE_S_LL_INFO);
MAKE_SYSTEM_PROP(LOG_LEVEL_WARN, ONE_S_LL_WARN);
MAKE_SYSTEM_PROP(LOG_LEVEL_ERROR, ONE_S_LL_ERROR);
MAKE_SYSTEM_PROP(LOG_LEVEL_FATAL, ONE_S_LL_FATAL);
MAKE_SYSTEM_PROP(LOG_LEVEL_VERBOSE, ONE_S_LL_VERBOSE);

@end
Binary file not shown.
2 changes: 1 addition & 1 deletion iphone/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 1.0.0
version: 1.1.0
apiversion: 2
architectures: armv7 arm64 i386 x86_64
description: com.williamrijksen.onesignal
Expand Down
4 changes: 2 additions & 2 deletions iphone/module.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
//
// IMPORTANT NOTE: always use $(inherited) in your overrides
//
FRAMEWORK_SEARCH_PATHS=$(SRCROOT)/../../modules/iphone/com.williamrijksen.onesignal/1.0.0/platform
FRAMEWORK_SEARCH_PATHS=$(SRCROOT)/../../modules/iphone/com.williamrijksen.onesignal/1.1.0/platform
OTHER_LDFLAGS=$(inherited) -framework OneSignal
LD_RUNPATH_SEARCH_PATHS= $(inherited) "@executable_path/Frameworks" $(FRAMEWORK_SEARCH_PATHS)
LD_RUNPATH_SEARCH_PATHS= $(inherited) "@executable_path/Frameworks" $(FRAMEWORK_SEARCH_PATHS)
4 changes: 2 additions & 2 deletions iphone/titanium.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
// OF YOUR TITANIUM SDK YOU'RE BUILDING FOR
//
//
TITANIUM_SDK_VERSION = 5.5.0.GA
TITANIUM_SDK_VERSION = 5.5.1.GA


//
// THESE SHOULD BE OK GENERALLY AS-IS
//
TITANIUM_SDK = /Users/williamrijksen/Library/Application Support/Titanium/mobilesdk/osx/5.5.0.GA
TITANIUM_SDK = ~/Library/Application Support/Titanium/mobilesdk/osx/$(TITANIUM_SDK_VERSION)
TITANIUM_BASE_SDK = "$(TITANIUM_SDK)/iphone/include"
TITANIUM_BASE_SDK2 = "$(TITANIUM_SDK)/iphone/include/TiCore"
TITANIUM_BASE_SDK3 = "$(TITANIUM_SDK)/iphone/include/JavaScriptCore"
Expand Down

0 comments on commit ed9d790

Please sign in to comment.