Use the Parse & Parse Live Query iOS SDK's in Axway Titanium! Read more about the Parse Live Query API in the official native repository.
- Swift 4.1 or later (embedded into the hook in
hooks/
) - Titanium SDK 6.3.0 or later (7.1.0.GA used in testing)
applicationId
(String)clientKey
(String)server
(String)localDatastoreEnabled
(Boolean)
applicationId
(String)clientKey
(String)server
(String)
className
(String)parameters
(Dictionary)callback
(Function)
query
(Query
)
className
(String)query
(String)
query
(Query
)
query
(Query
)
type
(EVENT_TYPE_*
)object
(Object
)query
(Query
)
error
(String)query
(Query
)
className
(String)predicate
(String, optional, e.g.name = "hans"
)
callback
(Function)
This project uses the following 5 Swift dependencies:
- Bolds
- BoldsSwift
- Parse
- ParseLiveQuery
- Starscream
While Bolds
and Parse
are Obj-C based, the others are dynamic Swift libraries. This projects resolves
all dependencies already for you, including setting the Swift version using the hook placed in hooks/
.
Right now, Titanium only supports CocoaPods for Hyperloop, so in order to use it for classic modules, you need
to create universal "fat" frameworks and strip the unused architectures again (this is taken care of by the SDK already).
A universal library can be created by grabbing the frameworks from Debug-iphonesimulator
(Simulator architectures)
and Debug-iphoneos
(Device architectures) and combine them using the following commands:
- Install CocoaPods (
sudo gem install cocoapods
) and runpod install
in thenative/
directory of this repository - Create the following folder structures:
sim/
,device/
&universal/
- Copy the .framework files from
Debug-iphonesimulator
tosim/
- Copy the .framework files from
Debug-iphoneos
todevice/
- Copy the .framework files from
device
touniversal/
(they are the base for universal frameworks) - For
BoldsSwift
andParseLiveQuery
, copy theModules/*.swiftmodule
to the universal directory of the framework - Use the following command to merge the sim- and device-frameworks together:
lipo -export -output universal/<name>.framework/<name> sim/<name>.framework/<name> device/<name>.framework/<name>
- Replace the final frameworks in
<module-project>/platform
- Make a pull request to this repo, so others can benefit from it as well
These steps are based on a Shell Script used natively.
Note: In the future, this will all be done by CocoaPods. Make sure to follow TIMOB-25927 regarding Swift support in the SDK.
var ParseLiveQuery = require('ti.livequery');
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var btn1 = Ti.UI.createButton({
title: 'Initialize Parse',
top: 100
});
var btn2 = Ti.UI.createButton({
title: 'Subscribe',
top: 200
});
btn1.addEventListener('click', function() {
ParseLiveQuery.initialize({
applicationId: '',
clientKey: '',
server: ''
});
});
btn2.addEventListener('click', function() {
var client = ParseLiveQuery.createClient({
applicationId: '',
clientKey: '',
server: ''
});
client.addEventListener('subscribe', function(e) {
Ti.API.info('Subscribed!');
// Subscribed
});
client.addEventListener('unsubscribe', function(e) {
Ti.API.info('Unsubscribed!');
// Unsubscribed
});
client.addEventListener('event', function(e) {
Ti.API.info('Event!');
printObject(e.object);
// Event received, check with e.type
});
client.addEventListener('error', function(e) {
Ti.API.info('Error!');
Ti.API.info(e.error);
// Error received, check with e.error
});
var query = ParseLiveQuery.createQuery({
className: 'Posts',
predicate: 'name = "Hans"'
});
client.subscribeToQuery(query);
// Get existing objects
query.findObjectsInBackground(function(e) {
Ti.API.info(e);
var objects = e.objects;
for (var i = 0; i < objects.length; i++) {
printObject(objects[i]);
}
})
});
// Utility method to print objects by using "objectForKey"
function printObject(object) {
var allKeys = object.allKeys;
for (var i = 0; i < allKeys.length; i++) {
var key = allKeys[i];
var value = object.objectForKey(key);
Ti.API.info(key + ' = ' + value);
}
}
win.add(btn1);
win.add(btn2);
win.open();
Hans Knöchel (@hansemannnn / Web)
Apache 2.0
Code contributions are greatly appreciated, please submit a new Pull-Request!