Skip to content

Commit

Permalink
Merge pull request #21 from chmiiller/master
Browse files Browse the repository at this point in the history
[iOS]Removes new framework keeping the last one
  • Loading branch information
williamrijksen authored Jan 30, 2017
2 parents e2e85f7 + 0163c2f commit a40ca58
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 29 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ Before setting up the Titanium SDK, you must generate the appropriate credential
Ti.API.info(Ti.Platform.osname === "iphone"? e.results : JSON.parse(e.results));
});
```
1. IdsAvailable (iOS-only for now):

```js
onesignal.idsAvailable(function(e) {
//pushToken will be nil if the user did not accept push notifications
alert(e);
});
```
1. postNotification (iOS-only for now):

```js
//You can use idsAvailable for retrieving a playerId
onesignal.postNotification({
message:'Titanium test message',
playerIds:["00000000-0000-0000-0000-000000000000"]
});
```
1. Set log level (iOS-only for now):

```js
Expand Down
101 changes: 82 additions & 19 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,92 @@
// open a single window
var win = Ti.UI.createWindow({
backgroundColor: 'white'
backgroundColor:'white'
});

var onesignal = require('com.williamrijksen.onesignal');

var scroll = Ti.UI.createScrollView({
layout: 'vertical',
top: 50
});
win.add(scroll);

var addTag = Ti.UI.createButton({
title: 'Add a tag',
width: Ti.UI.FILL,
height: Ti.UI.FILL,
color: 'black',
opacity: 0.8,
backgroundColor: 'transparent',
borderColor: '#4ee47f',
top: 60
});

addTag.addEventListener('click', function(e) {
onesignal.sendTag({
key: 'tag1',
value: true
});
alert('Tag added');
});
win.add(addTag);
title:'Add a tag',
width:Ti.UI.FILL,
height:40,
color:'black',
opacity:0.8,
backgroundColor:'transparent',
top:10
});

addTag.addEventListener('click',function(e){
onesignal.sendTag({key:'tag1', value:true});
alert('Tag added');
});
scroll.add(addTag);

var getTags = Ti.UI.createButton({
title:'Get all tags',
width:Ti.UI.FILL,
height:40,
color:'black',
opacity:0.8,
backgroundColor:'transparent',
top:10
});

getTags.addEventListener('click',function(e){
onesignal.getTags(function(e) {
if (!e.success) {
alert("Error: " + e.error);
return
}
alert(e.results);
setTimeout(function () {
var tags = JSON.parse(e.results);
alert(tags.length);
}, 2500);
});
});
scroll.add(getTags);

var getIds = Ti.UI.createButton({
title:'Get player ID',
width:Ti.UI.FILL,
height:40,
color:'black',
opacity:0.8,
backgroundColor:'transparent',
top:10
});

getIds.addEventListener('click',function(e){
onesignal.idsAvailable(function(e) {
//pushToken will be nil if the user did not accept push notifications
alert(e);
});
});
scroll.add(getIds);

var postNotificationButton = Ti.UI.createButton({
title:'Send a notification',
width:Ti.UI.FILL,
height:40,
color:'black',
opacity:0.8,
backgroundColor:'transparent',
top:10
});

postNotificationButton.addEventListener('click',function(e){
onesignal.postNotification({
message:'Titanium test message',
playerIds:["00000000-0000-0000-0000-000000000000"]
});
});
scroll.add(postNotificationButton);


onesignal.addEventListener("notificationOpened", function(evt) {
Expand Down
2 changes: 2 additions & 0 deletions ios/Classes/ComWilliamrijksenOnesignalModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ typedef void(^TagsResultHandler)(NSDictionary*, NSError*);
- (void)deleteTag:(id)args;
- (void)getTags:(id)value;
- (void)setLogLevel:(id)args;
- (void)idsAvailable:(id)args;
- (void)postNotification:(id)arguments;

@end
46 changes: 40 additions & 6 deletions ios/Classes/ComWilliamrijksenOnesignalModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ -(NSString*)moduleId
{
return @"com.williamrijksen.onesignal";
}

#pragma mark Lifecycle

- (void) receivedHandler:(OSNotification *)notification {
Expand Down Expand Up @@ -138,12 +138,12 @@ - (void)getTags:(id)args
@"success": NUMBOOL(error == nil),
}];

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

NSArray *invocationArray = [[NSArray alloc] initWithObjects:&propertiesDict count:1];
Expand All @@ -158,6 +158,40 @@ - (void)getTags:(id)args
}];
}

- (void)idsAvailable:(id)args
{
id value = args;
ENSURE_UI_THREAD(idsAvailable, value);
ENSURE_SINGLE_ARG(value, KrollCallback);

[OneSignal IdsAvailable:^(NSString* userId, NSString* pushToken) {
NSMutableDictionary *idsDict = [NSMutableDictionary dictionaryWithDictionary:@{
@"userId" : userId ?: @[],
@"pushToken" :pushToken ?: @[]
}];
NSArray *invocationArray = [[NSArray alloc] initWithObjects:&idsDict count:1];
[value call:invocationArray thisObject:self];
[invocationArray release];
}];
}

- (void)postNotification:(id)arguments
{
id args = arguments;
ENSURE_UI_THREAD_1_ARG(args);
ENSURE_SINGLE_ARG(args, NSDictionary);

NSString *message = [TiUtils stringValue:[args objectForKey:@"message"]];
NSArray *playerIds = [args valueForKey:@"playerIds"];

if(([message length] != 0) && ([playerIds count] != 0)){
[OneSignal postNotification:@{
@"contents" : @{@"en": message},
@"include_player_ids": playerIds
}];
}
}

- (void)setLogLevel:(id)arguments
{
id args = arguments;
Expand Down
8 changes: 4 additions & 4 deletions ios/com.williamrijksen.onesignal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
24DD6CFA1134B3F500162E58 /* ComWilliamrijksenOnesignalModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 24DD6CF81134B3F500162E58 /* ComWilliamrijksenOnesignalModule.m */; };
AA747D9F0F9514B9006C5449 /* ComWilliamrijksenOnesignal_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = AA747D9E0F9514B9006C5449 /* ComWilliamrijksenOnesignal_Prefix.pch */; };
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; };
E7E33C0C1D9D823200810B7E /* OneSignal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7E33C0B1D9D823200810B7E /* OneSignal.framework */; };
E84DA4BA1E3F8ACF00F5D794 /* OneSignal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E84DA4B91E3F8ACF00F5D794 /* OneSignal.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -46,16 +46,16 @@
AA747D9E0F9514B9006C5449 /* ComWilliamrijksenOnesignal_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ComWilliamrijksenOnesignal_Prefix.pch; sourceTree = SOURCE_ROOT; };
AACBBE490F95108600F1A2B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
D2AAC07E0554694100DB518D /* libComWilliamrijksenOnesignal.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libComWilliamrijksenOnesignal.a; sourceTree = BUILT_PRODUCTS_DIR; };
E7E33C0B1D9D823200810B7E /* OneSignal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OneSignal.framework; path = platform/OneSignal.framework; sourceTree = "<group>"; };
E84DA4B91E3F8ACF00F5D794 /* OneSignal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OneSignal.framework; path = platform/OneSignal.framework; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
D2AAC07C0554694100DB518D /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E84DA4BA1E3F8ACF00F5D794 /* OneSignal.framework in Frameworks */,
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */,
E7E33C0C1D9D823200810B7E /* OneSignal.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -84,7 +84,7 @@
0867D69AFE84028FC02AAC07 /* Frameworks */ = {
isa = PBXGroup;
children = (
E7E33C0B1D9D823200810B7E /* OneSignal.framework */,
E84DA4B91E3F8ACF00F5D794 /* OneSignal.framework */,
AACBBE490F95108600F1A2B1 /* Foundation.framework */,
);
name = Frameworks;
Expand Down

0 comments on commit a40ca58

Please sign in to comment.