Skip to content

NDEFPayload

treastrain edited this page May 17, 2021 · 2 revisions

NDEFPayload

public struct NDEFPayload 

Initializers

init(format:type:identifier:payload:)

os(iOS) && !targetEnvironment(macCatalyst)

Creates a payload record with the specified format, type, identifier, and payload data.

@available(iOS 13.0, *)
    public init(format: TypeNameFormat, type: Data, identifier: Data, payload: Data) 

This initializer uses the maximum payload chunk size defined by the NFC NDEF specification, which is 2^32-1 octets. If the payload size is bigger than the maximum size, the initializer splits the record into multiple record chunks.

Parameters

  • format: A NFC type name format value.
  • type: A data object describing the type of payload. If the data is empty, the method excludes this field from the payload record.
  • identifier: A URI reference that identifies the payload. If the data is empty, the method excludes this field from the payload record.
  • payload: A data object containing the payload data. If the data is empty, the method excludes this field from the payload record.

init(format:type:identifier:payload:chunkSize:)

os(iOS) && !targetEnvironment(macCatalyst)

Creates a payload record with the specified format, type, identifier, payload data, and data chunk size.

@available(iOS 13.0, *)
    public init(format: TypeNameFormat, type: Data, identifier: Data, payload: Data, chunkSize: Int) 

Parameters

  • format: A NFC type name format value.
  • type: A data object describing the type of payload. If the data is empty, the method excludes this field from the payload record.
  • identifier: A URI reference that identifies the payload. If the data is empty, the method excludes this field from the payload record.
  • payload: A data object containing the payload data. If the data is empty, the method excludes this field from the payload record.
  • chunkSize: The maximum size of a payload chunk. A value of zero indicates that the payload fits in a single record, that is, no chunking of the payload.

Properties

typeNameFormat

os(iOS) && !targetEnvironment(macCatalyst)

The Type Name Format field of the payload, as defined by the NDEF specification.

@available(iOS 11.0, *)
    public var typeNameFormat: TypeNameFormat 

type

os(iOS) && !targetEnvironment(macCatalyst)

The type of the payload, as defined by the NDEF specification.

@available(iOS 11.0, *)
    public var type: Data 

identifier

os(iOS) && !targetEnvironment(macCatalyst)

The identifier of the payload, as defined by the NDEF specification.

@available(iOS 11.0, *)
    public var identifier: Data 

payload

os(iOS) && !targetEnvironment(macCatalyst)

The payload, as defined by the NDEF specification.

@available(iOS 11.0, *)
    public var payload: Data 

Methods

wellKnownTypeURIPayload(url:)

os(iOS) && !targetEnvironment(macCatalyst)

Creates a payload record with a URI specified as a URL.

@available(iOS 13.0, *)
    public static func wellKnownTypeURIPayload(url: URL) -> Self? 

Parameters

  • url: A URL object.

Returns

An NDEF payload record.

wellKnownTypeURIPayload(string:)

os(iOS) && !targetEnvironment(macCatalyst)

Creates a payload record with a URI specified as a string.

@available(iOS 13.0, *)
    public static func wellKnownTypeURIPayload(string uri: String) -> Self? 

Use this method to create NDEF URI payload records that you can't create using a URL object, such as a URI containing special characters not represented by 7-bit ASCII encoding such as ä and ö.

Parameters

  • uri: A URL string.

Returns

An NDEF payload record.

wellKnownTypeTextPayload(string:locale:)

os(iOS) && !targetEnvironment(macCatalyst)

Creates a payload record with text.

@available(iOS 13.0, *)
    public static func wellKnownTypeTextPayload(string text: String, locale: Locale) -> Self? 

Parameters

  • text: Text to include in the payload.
  • locale: A locale object. This method saves the IANA language code, specified by the locale, to the payload.

Returns

An NDEF payload record.

wellKnownTypeTextPayload()

os(iOS) && !targetEnvironment(macCatalyst)

Returns the text and locale of a valid Well Known Type Text payload.

@available(iOS 13.0, *)
    public func wellKnownTypeTextPayload() -> (String?, Locale?) 

Returns

A tuple containing a string and locale from a Well Known Type Text payload. The string and locale can be nil.

wellKnownTypeURIPayload()

os(iOS) && !targetEnvironment(macCatalyst)

Returns the URL of a valid Well Known Type URI payload.

@available(iOS 13.0, *)
    public func wellKnownTypeURIPayload() -> URL? 

Returns

A URL when the payload contains a Well Know Type URI; otherwise, nil.

Clone this wiki locally