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

[TIMOB-18337][TIMOB-18627][TIMOB-18630] iOS: Extensions/WatchKit backport #6700

Merged
merged 12 commits into from
Mar 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions apidoc/Titanium/App/Properties/Properties.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Titanium.App.Properties
summary: |
The App Properties module is used for storing application-related data in property/value pairs
that persist beyond application sessions and device power cycles.

description: |
#### App Properties in the tiapp.xml file

App properties defined in the `tiapp.xml` file may be accessed using these APIs. An app
Expand Down Expand Up @@ -32,8 +32,6 @@ summary: |

Prior to Release 3.2.0, application properties defined in the `tiapp.xml` file could be
overwritten by these APIs and accessed externally by other applications and modules.

description: |

extends: Titanium.Module
since: "0.5"
Expand Down Expand Up @@ -244,7 +242,7 @@ events:
making a change using the Settings application.

The event is also fired when the application changes a property directly using one of the
`Ti.App.Properties` methods.
`Ti.App.iOS.UserDefaults` or `Ti.App.Properties` methods.
platforms: [iphone, ipad]
since: "3.0.0"

Expand Down
30 changes: 30 additions & 0 deletions apidoc/Titanium/App/iOS/UserDefaults.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Titanium.App.iOS.UserDefaults
summary: |
The UserDefaults module is used for storing application-related data in property/value pairs
that persist beyond application sessions and device power cycles. UserDefaults allows the suiteName
of the UserDefaults to be specified at creation time.
description: |
Unlike Titanium.App.Properties, Titanium.App.iOS.UserDefaults does not pull properties defined in the `tiapp.xml` file.

To create a notification action, use the <Titanium.App.iOS.createUserDefaults> method.
creatable: false
extends: Titanium.App.Properties
since: "4.0.0"
platforms: [iphone, ipad]

properties:
- name: suiteName
summary: Sets the name of the suite to be used to access UserDefaults.
type: String
availability: creation

examples:
- title: Create a UserDefaults object
example: |
Creating a UserDefaults object

var props = Ti.App.iOS.createUserDefaults({
suiteName: 'group.mySuite'
});

12 changes: 12 additions & 0 deletions apidoc/Titanium/App/iOS/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ platforms: [iphone, ipad]
since: "1.5"

methods:
- name: createUserDefaults
summary: |
Creates and returns an instance of Titanium.App.iOS.UserDefaults.
parameters:
- name: parameters
summary: Properties to set on a new object, including any defined by Titanium.App.iOS.UserDefaults except those marked not-creation or read-only.
type: Dictionary<Titanium.App.iOS.UserDefaults>

returns:
type: Titanium.App.iOS.UserDefaults
since: "4.0.0"

- name: cancelAllLocalNotifications
summary: Cancels all scheduled local notifications.

Expand Down
20 changes: 16 additions & 4 deletions apidoc/Titanium/Database/Database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ methods:
type: String
- name: dbName
summary: |
Destination filename, which will subsequently be passed to
Destination filename or absolute path, which will subsequently be passed to
<Titanium.Database.open>.
type: String
examples:
Expand Down Expand Up @@ -122,9 +122,9 @@ methods:
parameters:
- name: dbName
summary: |
The dbname previously passed to <Titanium.Database.install>. On Android,
an absolute path to the file, including one that is constructed with a
<Titanium.Filesystem> constant, may be used.
The dbname previously passed to <Titanium.Database.install>. An absolute path
to the file, including one that is constructed with a <Titanium.Filesystem>
constant or <Titanium.Filesystem.directoryForSuite> method, may be used.
type: String
examples:
- title: Open a Database from Internal Storage (iOS)
Expand Down Expand Up @@ -170,6 +170,18 @@ methods:
absolute path, as follows.

* `file:///sdcard/path/to/mydb2Installed`
- title: Open a Database in the shared directory of an application group (iOS)
example: |
Opens a Database in a shared directory

var suiteDir = Ti.Filesystem.directoryForSuite('group.appc.Sharing');
if (!suiteDir) {
logInApp('Suite Directory not found, check Entitlements.');
return;
}
var path = suiteDir + 'TestDB';
var db = Ti.Database.open(path);
db.close();
properties:
- name: FIELD_TYPE_DOUBLE
summary: Constant for requesting a column's value returned in double form.
Expand Down
29 changes: 29 additions & 0 deletions apidoc/Titanium/Filesystem/Filesystem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ description: |
as well as the other Filesystem submodule API documentation.
extends: Titanium.Module
since: "0.1"
examples:
- title: Getting a directory for an application group (iOS)
example: |
This example writes a string to a text file in a shared directory

var suiteDir = Ti.Filesystem.directoryForSuite('group.appc.Sharing');
if (!suiteDir) {
logInApp('Suite Directory not found, check Entitlements.');
return;
}
var f = Ti.Filesystem.getFile(suiteDir,'emptyfile.txt');
f.write('The file is no longer empty!');
methods:
- name: createTempDirectory
summary: Creates a temporary directory and returns a [File](Titanium.Filesystem.File) object representing the new directory.
Expand Down Expand Up @@ -80,6 +92,23 @@ methods:
returns:
type: Titanium.Filesystem.FileStream
exclude-platforms: [blackberry]
- name: directoryForSuite
summary: Returns the path to the container directory associated with the specified security application group ID.
description: |
This is a writable directory used on iOS. Groups of sandboxed apps that need to share files
and other information can request a container directory as part of their entitlements.

When called with a valid group identifier, this method returns the location of that directory as a string.
Returns null if the group identifier is invalid; check the app's entitlements.
parameters:
- name: suiteName
summary: |
The name of the suite.
type: String
returns:
type: String
platforms: [iphone, ipad]
since: "4.0.0"
properties:
- name: MODE_APPEND
summary: Constant for append mode for file operations.
Expand Down
11 changes: 11 additions & 0 deletions iphone/Classes/FilesystemModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ -(NSString*)tempDirectory
return [NSString stringWithFormat:@"%@/",fileURLify(NSTemporaryDirectory())];
}

-(id)directoryForSuite:(id)args
{
ENSURE_SINGLE_ARG(args, NSString);
NSURL *groupURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:args];
if (!groupURL) {
NSLog(@"[ERROR] Directory not found for suite: %@ check the com.apple.security.application-groups entitlement.", args);
return [NSNull null];
}
return [NSString stringWithFormat:@"%@/",fileURLify([groupURL path])];
}

-(NSString*)separator
{
return @"/";
Expand Down
16 changes: 16 additions & 0 deletions iphone/Classes/TiAppiOSProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "TiAppiOSLocalNotificationProxy.h"
#import "TiAppiOSNotificationActionProxy.h"
#import "TiAppiOSNotificationCategoryProxy.h"
#import "TiAppiOSUserDefaultsProxy.h"


@implementation TiAppiOSProxy
Expand Down Expand Up @@ -131,6 +132,21 @@ -(void)_listenerRemoved:(NSString*)type count:(int)count

#pragma mark Public

-(id)createUserDefaults:(id)args
{
NSString *suiteName;
ENSURE_SINGLE_ARG(args,NSDictionary);
ENSURE_ARG_FOR_KEY(suiteName, args, @"suiteName", NSString);

NSUserDefaults *defaultsObject = [[NSUserDefaults alloc] initWithSuiteName:suiteName];

TiAppiOSUserDefaultsProxy *userDefaultsProxy = [[[TiAppiOSUserDefaultsProxy alloc] _initWithPageContext:[self executionContext]] autorelease];

userDefaultsProxy.defaultsObject = defaultsObject;

return userDefaultsProxy;
}

-(id)registerBackgroundService:(id)args
{
NSDictionary* a = nil;
Expand Down
35 changes: 35 additions & 0 deletions iphone/Classes/TiAppiOSUserDefaultsProxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2015 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#import "TiProxy.h"

#ifdef USE_TI_APPIOS


@interface TiAppiOSUserDefaultsProxy : TiProxy
{
}

@property(nonatomic, retain) NSUserDefaults *defaultsObject;

-(id)getBool:(id)args;
-(id)getDouble:(id)args;
-(id)getInt:(id)args;
-(id)getString:(id)args;
-(id)getList:(id)args;
-(void)setBool:(id)args;
-(void)setDouble:(id)args;
-(void)setInt:(id)args;
-(void)setString:(id)args;
-(void)setList:(id)args;
-(void)removeProperty:(id)args;
-(void)removeAllProperties;
-(id)hasProperty:(id)args;
-(id)listProperties:(id)args;

@end

#endif