Instance Method インスタンスメソッド

containerURLForSecurityApplicationGroupIdentifier:

Returns the container directory associated with the specified security application group identifier. 指定されたセキュリティアプリケーショングループ識別子と結び付けられるコンテナディレクトリを返します。

Declaration 宣言

- (NSURL *)containerURLForSecurityApplicationGroupIdentifier:(NSString *)groupIdentifier;

Parameters パラメータ

groupIdentifier

A string that names the group whose shared directory you want to obtain. あなたが取得するのを望む共有ディレクトリをそれが持つグループを指名する文字列。 This input should exactly match one of the strings in the app's App Groups Entitlement.

Return Value 戻り値

A URL indicating the location of the group's shared directory in the file system. In iOS, the value is nil when the group identifier is invalid. In macOS, a URL of the expected form is always returned, even if the app group is invalid, so be sure to test that you can access the underlying directory before attempting to use it. ファイルシステムにおいてグループの持つ共有ディレクトリの位置を指し示すURL。iOSでは、この値はグループ識別子が無効である場合はnilです。macOSでは、期待される形式のURLが常に返されます、アプリのグループが無効であってさえもです、なのであなたがそれを使おうと試みる前に基底ディレクトリにアクセス可能であることのテストを確実にしてください。

Discussion 議論

Sandboxed apps in macOS and all apps in iOS that need to share files with other apps from the same developer on a given device use the App Groups Entitlement to join one or more application groups. The entitlement consists of an array of group identifier strings that indicate the groups to which the app belongs, as described in Adding an App to an App Group in Entitlement Key Reference.

You use one of these group identifier strings to locate the corresponding group's shared directory. When you call containerURLForSecurityApplicationGroupIdentifier: with one of your app's group identifiers, the method returns an NSURL instance specifying the location in the file system of that group's shared directory. The behavior of application groups differs between macOS and iOS. あなたは、それらグループ識別子の文字列の1つを使って、対応するグループの持つ共有ディレクトリの位置を突き止めます。あなたがcontainerURLForSecurityApplicationGroupIdentifier:をあなたのアプリの持つグループ識別子の1つで呼び出す場合、メソッドは、そのグループの共有ディレクトリのファイルシステムにおける位置を指定しているNSURLインスタンスを返します。アプリケーショングループの挙動は、macOSとiOSで異なります。

App Groups in macOS macOSでのアプリグループ

For a sandboxed app in macOS, the group directory is located at ~/Library/Group Containers/<application-group-id>, where the application group identifier begins with the developer's team identifier followed by a dot, followed by the specific group name. The system creates this directory automatically the first time your app needs it and never removes it. macOSでのサンドボックスアプリでは、グループディレクトリは~/Library/Group Containers/<application-group-id>に位置します、そこにおいてアプリケーショングループ識別子は開発者の持つチーム識別子に1つのドットが続くことで始まり、特定のグループ名が続きます。システムは、このディレクトリをあなたのアプリがそれを必要とする最初の時に自動的に作成します、そして決してそれを除去しません。

The system also creates the Library/Application Support, Library/Caches, and Library/Preferences subdirectories inside the group directory the first time you use it. You are free to add or remove subdirectories as you see fit, but you are encouraged to use these standardized locations as you would in the app's usual container. システムはまた、Library/Application SupportLibrary/Caches、そしてLibrary/Preferences下位ディレクトリをグループディレクトリの内部にあなたがそれを最初に使う時に作成します。あなたは、あなたが適当と思う通りに自由に下位ディレクトリを追加または除去します、しかしあなたはそれら標準化された場所をあなたがアプリの持つ通常のコンテナの中でするように使うのは推奨されません。

If you call the method with an invalid group identifier, namely one for which you do not have an entitlement, the method still returns a URL of the expected form, but the corresponding group directory does not actually exist, nor can your sandboxed app create it. Therefore be sure to test that you can successfully access the returned URL before using it. あなたがメソッドを無効なグループ識別子、言い換えるとそれに対してあなたが資格を持たないもので呼び出すならば、メソッドは依然として期待する形式のURlを返します、しかし対応するグループディレクトリは実際には存在しませんし、あなたのサンドボックスアプリはそれを作成もできません。それゆえにあなたが返されるURLにうまくアクセスできることをそれを使う前にテストするのを確実にしてください。

App Groups in iOS iOSでのアプリグループ

In iOS, the group identifier starts with the word group and a dot, followed by the group name. However, the system makes no guarantee about the group directory's name or location in the file system. Indeed, the directory is accessible only with the file URL returned by this method. As in macOS, the system creates the directory when you need it. Unlike in macOS, when all the apps in a given app group are removed from the device, the system detects this condition and removes the corresponding group directory as well. iOSでは、グループ識別子は単語groupと1つのドットで始まり、グループ名が続きます。しかしながら、システムはファイルシステムにおいてグループディレクトリの持つ名前または位置について保証することをしません。本当に、ディレクトリはこのメソッドによって返されるファイルURLでのみアクセス可能です。macOSでのように、システムはディレクトリをあなたがそれを必要とする時に作成します。macOSとは違い、与えられたアプリグループの中のアプリ全てがデバイスから除去される場合、システムはこの状態を検知して、対応するグループディレクトリもまた削除します。

The system creates only the Library/Caches subdirectory automatically, but you can create others yourself if you need them. You are free to use the group directory as you see fit, but take care to coordinate its structure among all the group's apps. システムは、ただLibrary/Caches下位ディレクトリだけを自動的に作成します、しかしあなたは他のものをあなた自身で作成できます、あなたがそれらを必要とするならば。あなたは、グループディレクトリを自由にあなたが適当と思う通りに使います、しかしグループの持つアプリ全ての間で、それの構造を調和させるように注意してください。

If you call the method with an invalid group identifier in iOS, the method returns a nil value. あなたがメソッドを不正なグループ識別子でiOSにおいて呼び出すならば、メソッドはnil値を返します。

See Also 参照

Locating Application Group Container Directories アプリケーショングループコンテナディレクトリの位置決めをする