Skip to content

Commit

Permalink
fix naming convention in WatchSession
Browse files Browse the repository at this point in the history
  • Loading branch information
cheekiatng committed Aug 29, 2015
1 parent ba7f539 commit 58f34dc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 55 deletions.
67 changes: 33 additions & 34 deletions apidoc/Titanium/WatchSession/WatchSession.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ properties:
permission: read-only
osver: {ios: {min: "9.0"}}
platforms: [iphone,ipad]
- name: recentAppContext
- name: recentApplicationContext
summary: The most recent application context sent to the watch app.
type: Dictionary
permission: read-only
osver: {ios: {min: "9.0"}}
platforms: [iphone,ipad]
methods:
- name: activate
- name: activateSession
summary: |
Activates the watch session
description: |
Expand All @@ -63,7 +63,7 @@ methods:
type: Dictionary
platforms: [iphone, ipad]
osver: {ios: {min: "9.0"}}
- name: updateAppContext
- name: updateApplicationContext
summary: |
Sends an app context update to the apple watch.
description: |
Expand Down Expand Up @@ -137,31 +137,31 @@ methods:
platforms: [iphone, ipad]
osver: {ios: {min: "9.0"}}
events:
- name: watchSessionReceivedMessage
- name: receivemessage
summary: |
App received message from apple watch in foreground.
properties:
- name: message
summary: message content
type: Dictionary
platforms: [iphone, ipad]
- name: watchSessionReceivedAppContext
- name: receiveapplicationcontext
summary: |
App received app context from apple watch.
properties:
- name: appContext
summary: app Context
- name: applicationContext
summary: application Context
type: Dictionary
platforms: [iphone, ipad]
- name: watchSessionReceivedUserInfo
- name: receiveuserinfo
summary: |
App received user info from apple watch in background.
properties:
- name: userInfo
summary: user info content
type: Dictionary
platforms: [iphone, ipad]
- name: watchSessionReceivedFile
- name: receivefile
summary: |
App received file from apple watch in background.
properties:
Expand All @@ -185,7 +185,7 @@ events:
summary: Error message if any.
type: String
platforms: [iphone, ipad]
- name: watchStateChanged
- name: watchstatechanged
summary: |
The watch state has changed.
properties:
Expand All @@ -201,15 +201,15 @@ events:
summary: If the complication is enabled in the apple watch.
type: Boolean
platforms: [iphone, ipad]
- name: watchReachabilityChanged
- name: reachabilitychanged
summary: |
The watch reachability state has changed.
properties:
- name: isReachable
summary: If apple watch is currently reachable.
type: Boolean
platforms: [iphone, ipad]
- name: watchSessionFinishedUserInfoTransfer
- name: finishuserinfotransfer
summary: |
Fired when the application completed user info transfer to the watch app.
properties:
Expand All @@ -229,7 +229,7 @@ events:
summary: Error message if any.
type: String
platforms: [iphone, ipad]
- name: watchSessionFinishedFileTransfer
- name: finishfiletransfer
summary: |
App completed file transfer to watch app.
properties:
Expand Down Expand Up @@ -264,7 +264,7 @@ examples:
#### app.js
Ti.WatchSession.activate();
Ti.WatchSession.activateSession();
var win = Ti.UI.createWindow({
backgroundColor: 'white'
Expand Down Expand Up @@ -304,7 +304,7 @@ examples:
+ '\nwatchApp is installed: ' + Ti.WatchSession.isWatchAppInstalled
+ '\nwatchComplication is enabled: ' + Ti.WatchSession.isComplicationEnabled
+ '\nwatch is reachable: ' + Ti.WatchSession.isReachable
+ '\nMost recent app context: ' + JSON.stringify(Ti.WatchSession.recentAppContext);
+ '\nMost recent app context: ' + JSON.stringify(Ti.WatchSession.recentApplicationContext);
})
win.add(statusBtn);
Expand Down Expand Up @@ -339,9 +339,8 @@ examples:
});
sendAppContextBtn.addEventListener('click', function(e) {
//only the latest appContext is registered. Send 2 to test.
Ti.WatchSession.updateAppContext({
status: 'AppContext from app',
Ti.WatchSession.updateApplicationContext({
status: 'Application Context from app',
updates: 2
});
});
Expand All @@ -360,46 +359,46 @@ examples:
});
});
Ti.WatchSession.addEventListener('watchSessionReceivedMessage', function(e) {
eventsArea.value += '\nwatchSessionReceivedMessage '
Ti.WatchSession.addEventListener('receivemessage', function(e) {
eventsArea.value += '\nreceivemessage '
+ '\n' + JSON.stringify(e);
});
Ti.WatchSession.addEventListener('watchSessionReceivedUserInfo', function(e) {
eventsArea.value += '\nwatchSessionReceivedUserInfo '
Ti.WatchSession.addEventListener('receiveuserinfo', function(e) {
eventsArea.value += '\nreceiveuserinfo '
+ '\n' + JSON.stringify(e);
});
Ti.WatchSession.addEventListener('watchSessionReceivedFile', function(e) {
eventsArea.value += '\nwatchSessionReceivedFile ' + '\n' + JSON.stringify(e);
Ti.WatchSession.addEventListener('receivefile', function(e) {
eventsArea.value += '\nreceivefile ' + '\n' + JSON.stringify(e);
var cacheFile = e.data.getFile();
var downloadedFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, cacheFile.getName());
downloadedFile.write(e.data);
imageView.setImage(downloadedFile);
});
Ti.WatchSession.addEventListener('watchSessionReceivedAppContext', function(e) {
eventsArea.value += '\nwatchSessionReceivedAppContext '
Ti.WatchSession.addEventListener('receiveapplicationcontext', function(e) {
eventsArea.value += '\nreceiveapplicationcontext '
+ '\n' + JSON.stringify(e);
});
Ti.WatchSession.addEventListener('watchStateChanged', function(e) {
eventsArea.value += '\nwatchStateChanged '
Ti.WatchSession.addEventListener('watchstatechanged', function(e) {
eventsArea.value += '\nwatchstatechanged '
+ '\n' + JSON.stringify(e);
});
Ti.WatchSession.addEventListener('watchReachabilityChanged', function(e) {
eventsArea.value += '\nwatchReachabilityChanged '
Ti.WatchSession.addEventListener('reachabilitychanged', function(e) {
eventsArea.value += '\nreachabilitychanged '
+ '\n' + JSON.stringify(e);
});
Ti.WatchSession.addEventListener('watchSessionFinishedFileTransfer', function(e) {
eventsArea.value += '\nwatchSessionFinishedFileTransfer '
Ti.WatchSession.addEventListener('finishfiletransfer', function(e) {
eventsArea.value += '\nfinishfiletransfer '
+ '\n' + JSON.stringify(e);
});
Ti.WatchSession.addEventListener('watchSessionFinishedUserInfoTransfer', function(e) {
eventsArea.value += '\nwatchSessionFinishedUserInfoTransfer '
Ti.WatchSession.addEventListener('finishuserinfotransfer', function(e) {
eventsArea.value += '\nfinishuserinfotransfer '
+ '\n' + JSON.stringify(e);
});
win.add(sendMsgBtn);
Expand Down
42 changes: 21 additions & 21 deletions iphone/Classes/WatchSessionModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ -(NSNumber*)isReachable
}

//copy of most recent app context sent to watch
-(NSDictionary*)recentAppContext
-(NSDictionary*)recentApplicationContext
{
if ([WCSession isSupported] == YES) {
return [[self watchSession] applicationContext];
Expand All @@ -93,7 +93,7 @@ -(NSDictionary*)recentAppContext
}

#pragma mark watch session methods
-(void)activate:(id)value
-(void)activateSession:(id)value
{
[self watchSession];
}
Expand All @@ -112,7 +112,7 @@ -(void)sendMessage:(id)value
[[self watchSession] sendMessage:value replyHandler:nil errorHandler:nil];
}
//sent to watch so that it can update its state when it wakes
-(void)updateAppContext:(id)value
-(void)updateApplicationContext:(id)value
{
if ([WCSession isSupported] == NO) {
DebugLog(@"[ERROR] Target does not support watch connectivity");
Expand Down Expand Up @@ -227,53 +227,53 @@ -(void)cancelAllTransfers:(id)value
#pragma mark watch session delegates
- (void)session:(nonnull WCSession *)session didReceiveMessage:(nonnull NSDictionary<NSString *,id> *)message
{
if([self _hasListeners:@"watchSessionReceivedMessage"]){
if([self _hasListeners:@"receivemessage"]){
NSDictionary *dict = [NSDictionary dictionaryWithObject:message forKey:@"message"];
[self fireEvent:@"watchSessionReceivedMessage" withObject:dict];
[self fireEvent:@"receivemessage" withObject:dict];
}
}
//these are context updates received right after [watchSession activate]
//these are context updates received right after [watchSession activateSession]
- (void)session:(nonnull WCSession *)session didReceiveApplicationContext:(nonnull NSDictionary<NSString *,id> *)applicationContext
{
if([self _hasListeners:@"watchSessionReceivedAppContext"]){
NSDictionary *dict = [NSDictionary dictionaryWithObject:applicationContext forKey:@"appContext"];
[self fireEvent:@"watchSessionReceivedAppContext" withObject:dict];
if([self _hasListeners:@"receiveapplicationcontext"]){
NSDictionary *dict = [NSDictionary dictionaryWithObject:applicationContext forKey:@"applicationContext"];
[self fireEvent:@"receiveapplicationcontext" withObject:dict];
}
}

-(void)session:(nonnull WCSession *)session didReceiveUserInfo:(nonnull NSDictionary<NSString *,id> *)userInfo
{
if([self _hasListeners:@"watchSessionReceivedUserInfo"]){
if([self _hasListeners:@"receiveuserinfo"]){
NSDictionary *dict = [NSDictionary dictionaryWithObject:userInfo forKey:@"userInfo"];
[self fireEvent:@"watchSessionReceivedUserInfo" withObject:dict];
[self fireEvent:@"receiveuserinfo" withObject:dict];
}
}

-(void)sessionWatchStateDidChange:(nonnull WCSession *)session
{
if([self _hasListeners:@"watchStateChanged"]){
if([self _hasListeners:@"watchstatechanged"]){
NSDictionary *dict = [NSDictionary
dictionaryWithObjectsAndKeys:NUMBOOL([session isPaired]),@"isPaired",
NUMBOOL([session isWatchAppInstalled]),@"isWatchAppInstalled",
NUMBOOL([session isComplicationEnabled]),@"isComplicationEnabled",
nil];
[self fireEvent:@"watchStateChanged" withObject:dict];
[self fireEvent:@"watchstatechanged" withObject:dict];
}
}

-(void)sessionReachabilityDidChange:(nonnull WCSession *)session
{
if([self _hasListeners:@"watchReachabilityChanged"]){
if([self _hasListeners:@"reachabilitychanged"]){
NSDictionary *dict = [NSDictionary
dictionaryWithObjectsAndKeys:NUMBOOL([session isReachable]),@"isReachable",
nil];
[self fireEvent:@"watchReachabilityChanged" withObject:dict];
[self fireEvent:@"reachabilitychanged" withObject:dict];
}
}

-(void)session:(WCSession * _Nonnull)session didFinishUserInfoTransfer:(nonnull WCSessionUserInfoTransfer *)userInfoTransfer error:(nullable NSError *)error
{
if([self _hasListeners:@"watchSessionFinishedUserInfoTransfer"]){
if([self _hasListeners:@"finishuserinfotransfer"]){
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[userInfoTransfer userInfo], @"userInfo",
nil];
Expand All @@ -290,13 +290,13 @@ -(void)session:(WCSession * _Nonnull)session didFinishUserInfoTransfer:(nonnull
nil];
[dict addEntriesFromDictionary:success];
}
[self fireEvent:@"watchSessionFinishedUserInfoTransfer" withObject:dict];
[self fireEvent:@"finishuserinfotransfer" withObject:dict];
}
}

-(void)session:(nonnull WCSession *)session didReceiveFile:(nonnull WCSessionFile *)file
{
if([self _hasListeners:@"watchSessionReceivedFile"]){
if([self _hasListeners:@"receivefile"]){
NSError *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *destinationFilename = [[file fileURL] lastPathComponent];
Expand Down Expand Up @@ -329,13 +329,13 @@ -(void)session:(nonnull WCSession *)session didReceiveFile:(nonnull WCSessionFil
nil];
[dict addEntriesFromDictionary:success];
}
[self fireEvent:@"watchSessionReceivedFile" withObject:dict];
[self fireEvent:@"receivefile" withObject:dict];
}
}

-(void)session:(nonnull WCSession *)session didFinishFileTransfer:(nonnull WCSessionFileTransfer *)fileTransfer error:(nullable NSError *)error
{
if([self _hasListeners:@"watchSessionFinishedFileTransfer"]){
if([self _hasListeners:@"finishfiletransfer"]){
WCSessionFile *file = [fileTransfer file];
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[file fileURL], @"fileURL",
Expand All @@ -354,7 +354,7 @@ -(void)session:(nonnull WCSession *)session didFinishFileTransfer:(nonnull WCSes
nil];
[dict addEntriesFromDictionary:success];
}
[self fireEvent:@"watchSessionFinishedFileTransfer" withObject:dict];
[self fireEvent:@"finishfiletransfer" withObject:dict];
}
}

Expand Down

0 comments on commit 58f34dc

Please sign in to comment.