PyzeiMessageApps

@interface PyzeiMessageApps : PyzeMessaging

### PyzeiMessageApps Subclass of PyzeCustomEvent can be used to post events related to iMessage apps and extensions.

Since

v2.7.0
  • Post insert message details.

    Usage:

      -(void) insertMessageOnCurrentConversation {
          MSConversation * conversation = self.activeConversation;
          if (conversation) {
          MSMessageTemplateLayout * activeLayout = [[MSMessageTemplateLayout alloc] init];
          activeLayout.image = image;
          activeLayout.caption = @"Message Counter";
          activeLayout.subcaption = @"Message subcaption";
          activeLayout.trailingCaption = @"Trailing caption";
          activeLayout.trailingSubcaption = @"Trailing Subcaption";
          activeLayout.mediaFileURL = [NSURL URLWithString:@"Path to media URL"];
          activeLayout.imageTitle = @"Image counter";
          activeLayout.imageSubtitle = @"Image subtitle";
    
          MSMessage * message = [[MSMessage alloc] init];
          message.layout = activeLayout;
          message.URL = [NSURL URLWithString:@"Empty URL"];
          message.summaryText = @"This is Summary";
    
          [conversation insertMessage:message completionHandler:^(NSError * error) {
              NSMutableDictionary * dictionary = [self fillMessagingAttributes:message 
                                                                  conversation:conversation];
    
              dictionary[@"additional attributes"] = "may be set before calling";
              [PyzeiMessageApps postInsertMessageWithAttributes: dictionary];
          }];
          }
      }
    
      -(NSMutableDictionary *) fillMessagingAttributes:(MSMessage *)message
                                          conversation:(MSConversation *)conversation
      {
          NSMutableDictionary * attributes = [NSMutableDictionary dictionary];
          // Message details
          if (message) {
              if (message.URL) attributes[@"URL"] = @"1";
              if (message.summaryText) attributes[@"summaryText"] = @"1";
          }
          // message layout details
          MSMessageTemplateLayout * layout = (MSMessageTemplateLayout *)message.layout;
          if (layout) {
              if (layout.caption) attributes[@"caption"] = @"1";
              if (layout.subcaption) attributes [@"subcaption"] = @"1";
              if (layout.trailingCaption) attributes[@"trailingCaption"] = @"1";
              if (layout.trailingSubcaption) attributes[@"trailingSubcaption"] = @"1";
              if (layout.image) attributes[@"image"] = @"1";
              if (layout.mediaFileURL) attributes[@"mediaFileURL"] =  @"1";
              if (layout.imageTitle) attributes[@"imageTitle"] = @"1";
              if (layout.imageSubtitle) attributes[@"imageSubtitle"] = @"1";
          }
          // conversation details
          if (conversation) {
              attributes[@"localParticipantHash"] = [Pyze hash:[conversation.localParticipantIdentifier UUIDString]];
              if (conversation.remoteParticipantIdentifiers) 
                   attributes[@"remoteParticipants"] = @(conversation.remoteParticipantIdentifiers.count);
    
              NSMutableString * remoteParticipantHashes = [NSMutableString string];
              for (NSUUID * uuid in conversation.remoteParticipantIdentifiers) {
                  [remoteParticipantHashes appendString:[Pyze hash:[uuid UUIDString]]];
              }
    
              if (remoteParticipantHashes && remoteParticipantHashes.length) 
                  attributes[@"remoteParticipantsHashes"] = remoteParticipantHashes;
          }
          return attributes;
       }
    

    Declaration

    Objective-C

    + (void)postInsertMessageWithAttributes:
        (nonnull NSMutableDictionary *)attributes;

    Swift

    class func postInsertMessage(withAttributes attributes: Any!)

    Parameters

    attributes

    Additional attributes.

  • Post insert sticker details.

    Usage:

      -(void) insertStickerOnCurrentConversation {
          MSConversation * conversation = self.activeConversation;
          if (conversation) {
              MSSticker * sticker = [[MSSticker alloc] initWithContentsOfFileURL:[NSURL URLWithString:@"URL to sticker file"]
                                                            localizedDescription:@"description"
                                                                           error:nil];
    
              [conversation insertSticker:sticker completionHandler:^(NSError * _Nullable) {
              NSMutableDictionary * attributes = [NSMutableDictionary dictionary];
    
              // conversation details
              attributes[@"localParticipantHash"] = [Pyze hash:[conversation.localParticipantIdentifier UUIDString]];
              if (conversation.remoteParticipantIdentifiers)
                   attributes[@"remoteParticipants"] = @(conversation.remoteParticipantIdentifiers.count);
    
              NSMutableString * remoteParticipantHashes = [NSMutableString string];
              for (NSUUID * uuid in conversation.remoteParticipantIdentifiers) {
                  [remoteParticipantHashes appendString:[Pyze hash:[uuid UUIDString]]];
              }
    
              if (remoteParticipantHashes && remoteParticipantHashes.length)
                  attributes[@"remoteParticipantsHashes"] = remoteParticipantHashes;
    
              [PyzeiMessageApps postInsertStickerWithLocalizedDescription:sticker.localizedDescription.length
                                            withStickerImageFileURLString:[sticker.imageFileURL absoluteString].length
                                                           withAttributes:attributes];
              }];
          }
        }
    

    Declaration

    Objective-C

    + (void)postInsertStickerWithLocalizedDescription:(BOOL)descriptionProvided
                        withStickerImageFileURLString:(BOOL)URLstringProvided
                                       withAttributes:
                                           (nonnull NSMutableDictionary *)
                                               attributes;

    Swift

    class func postInsertSticker(withLocalizedDescription descriptionProvided: Any!, withStickerImageFileURLString URLstringProvided: Any!, withAttributes attributes: Any!)

    Parameters

    descriptionProvided

    Boolean value to check whether description provided or not.

    URLstringProvided

    URL to sticker is provided or not.

    attributes

    Other attributes to be processed.

  • Post insert text details.

    Usage:

      -(void) insertTextOnCurrentConversation {
          MSConversation * conversation = self.activeConversation;
          if (conversation) {
              [conversation insertText:@"Pyze" completionHandler:^(NSError * error) {
                  NSMutableDictionary * attributes = [NSMutableDictionary dictionary];
    
                  // conversation details
                  attributes[@"localParticipantHash"] = [Pyze hash:[conversation.localParticipantIdentifier UUIDString]];
                  if (conversation.remoteParticipantIdentifiers)
                      attributes[@"remoteParticipants"] = @(conversation.remoteParticipantIdentifiers.count);
    
                      NSMutableString * remoteParticipantHashes = [NSMutableString string];
                      for (NSUUID * uuid in conversation.remoteParticipantIdentifiers) {
                      [remoteParticipantHashes appendString:[Pyze hash:[uuid UUIDString]]];
                  }
    
                  if (remoteParticipantHashes && remoteParticipantHashes.length)
                      attributes[@"remoteParticipantsHashes"] = remoteParticipantHashes;
    
                  [PyzeiMessageApps postInsertTextWithText:true withAttributes:attributes];
              }];
         }
      }
    

    Declaration

    Objective-C

    + (void)postInsertTextWithText:(BOOL)textProvided
                    withAttributes:(nonnull NSMutableDictionary *)attributes;

    Swift

    class func postInsertText(withText textProvided: Any!, withAttributes attributes: Any!)

    Parameters

    textProvided

    True if text provided or false.

    attributes

    Other attributes to process.

  • Post insert attachment details.

    Usage:

      -(void) insertAttachmentOnCurrentConversation {
          MSConversation * conversation = self.activeConversation;
          if (conversation) {
              [conversation insertAttachment:[NSURL URLWithString:@"URL to attachment"]
                       withAlternateFilename:@"My Attachement"
                           completionHandler:^(NSError * error)
              {
    
                  NSMutableDictionary * attributes = [NSMutableDictionary dictionary];
    
                  // conversation details
                  attributes[@"localParticipantHash"] = [Pyze hash:[conversation.localParticipantIdentifier UUIDString]];
                  if (conversation.remoteParticipantIdentifiers)
                      attributes[@"remoteParticipants"] = @(conversation.remoteParticipantIdentifiers.count);
    
                      NSMutableString * remoteParticipantHashes = [NSMutableString string];
                      for (NSUUID * uuid in conversation.remoteParticipantIdentifiers) {
                      [remoteParticipantHashes appendString:[Pyze hash:[uuid UUIDString]]];
                  }
    
                  if (remoteParticipantHashes && remoteParticipantHashes.length)
                      attributes[@"remoteParticipantsHashes"] = remoteParticipantHashes;
    
                  [PyzeiMessageApps postInsertAttachmentWithURL:true
                                          withAlternateFileName:true
                                                 withAttributes:attributes];
               }];
           }
        }
    

    Declaration

    Objective-C

    + (void)postInsertAttachmentWithURL:(BOOL)URLProvided
                  withAlternateFileName:(BOOL)fileNameProvided
                         withAttributes:(nonnull NSMutableDictionary *)attributes;

    Swift

    class func postInsertAttachment(withURL URLProvided: Any!, withAlternateFileName fileNameProvided: Any!, withAttributes attributes: Any!)

    Parameters

    URLProvided

    True if url to attachment provided.

    fileNameProvided

    True if alternate filename provided for attachment

    attributes

    Other attributes to process.

  • Post message start sending details.

    Usage:

      // Called when the user taps the send button.
      -(void)didStartSendingMessage:(MSMessage *)message conversation:(MSConversation *)conversation {
    
          NSMutableDictionary * attributes = [self fillMessagingAttributes:message conversation:conversation];
          attributes = [self fillMessagingAttributes:message conversation:conversation];
          attributes[@"additional attributes"] = "may be set before calling";
    
          [PyzeiMessageApps postMessageStartSendingWithAttributes:attributes];
      }
    
      -(NSMutableDictionary *) fillMessagingAttributes:(MSMessage *)message conversation:(MSConversation *)conversation
      {
          // See fillMessagingAttributes in postInsertMessageWithAttributes.
      }
    

    Declaration

    Objective-C

    + (void)postMessageStartSendingWithAttributes:
        (nonnull NSMutableDictionary *)attributes;

    Swift

    class func postMessageStartSending(withAttributes attributes: Any!)

    Parameters

    attributes

    Other attributes to process.

  • Post receive message details.

    Usage:

      // Called when a message arrives that was generated by another instance of this extension on a remote device.
      -(void)didReceiveMessage:(MSMessage *)message conversation:(MSConversation *)conversation {
    
          [PyzeiMessageApps postReceiveMessageWithAttributes:[self fillMessagingAttributes:message conversation:conversation]];
      }
    
      -(NSMutableDictionary *) fillMessagingAttributes:(MSMessage *)message conversation:(MSConversation *)conversation
      {
          // See fillMessagingAttributes in postInsertMessageWithAttributes. 
      }
    

    Declaration

    Objective-C

    + (void)postReceiveMessageWithAttributes:
        (nonnull NSMutableDictionary *)attributes;

    Swift

    class func postReceiveMessage(withAttributes attributes: Any!)

    Parameters

    attributes

    Other attributes to process.

  • Post cancel sending message details.

    Usage:

      // Called when the user deletes the message without sending it.
      -(void)didCancelSendingMessage:(MSMessage *)message conversation:(MSConversation *)conversation {
    
          [PyzeiMessageApps postCancelSendingMessageWithAttributes:[self fillMessagingAttributes:message conversation:conversation]];
      }
    
      -(NSMutableDictionary *) fillMessagingAttributes:(MSMessage *)message conversation:(MSConversation *)conversation
      {
          // See fillMessagingAttributes in postInsertMessageWithAttributes.
      }
    

    Declaration

    Objective-C

    + (void)postCancelSendingMessageWithAttributes:
        (nonnull NSMutableDictionary *)attributes;

    Swift

    class func postCancelSendingMessage(withAttributes attributes: Any!)

    Parameters

    attributes

    Other attributes to process.