Added comments describing ShareExtensionManager public functionality + small method renaming

This commit is contained in:
Aram Sargsyan 2017-08-18 02:27:56 +04:00
parent 37bd161f1d
commit 5641204318
3 changed files with 53 additions and 14 deletions

View file

@ -19,34 +19,71 @@
@class ShareExtensionManager;
/**
The protocol for the manager's delegate
*/
@protocol ShareExtensionManagerDelegate <NSObject>
@required
/**
Called when an image is going to be shared to show a compression prompt
@param extensionManager the ShareExtensionManager object that called the method
@param compressionPrompt the prompt that was prepared for the image which is going to be shared
*/
- (void)shareExtensionManager:(ShareExtensionManager *)extensionManager showImageCompressionPrompt:(UIAlertController *)compressionPrompt;
@optional
/**
Called when the progress of the uploading media changes
@param extensionManager the ShareExtensionManager object that called the method
@param progress the current progress
*/
- (void)shareExtensionManager:(ShareExtensionManager *)extensionManager mediaUploadProgress:(CGFloat)progress;
@end
/**
A class used to share content from the extension
*/
@interface ShareExtensionManager : NSObject
/**
The share extension context that represents a user's sharing request, also stores the content to be shared
*/
@property (nonatomic) NSExtensionContext *shareExtensionContext;
/**
A delegate used to notify about needed UI changes when sharing
*/
@property (nonatomic) id<ShareExtensionManagerDelegate> delegate;
/**
The singleton instance
*/
+ (instancetype)sharedManager;
/**
Send the content that the user has chosen to a room
@param room the room to send the content to
@param failureBlock the code to be executed when sharing has failed for whatever reason
note: there is no "successBlock" parameter because when the sharing succeds, the extension needs to close itself
*/
- (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)())failureBlock;
/**
Checks if there is an image in the user chosen content
@return YES if there is, NO otherwise
*/
- (BOOL)hasImageTypeContent;
- (void)cancelSharing;
- (void)cancelSharingWithFailure;
- (UIAlertController *)compressionPromptForImage:(UIImage *)image shareBlock:(nonnull void(^)())shareBlock;
/**
Terminate the extension and return to the app that started it
@param canceled YES if the user chose to cancel the sharing, NO otherwise
*/
- (void)terminateExtensionCanceled:(BOOL)canceled;
@end

View file

@ -152,14 +152,16 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
return NO;
}
- (void)cancelSharing
- (void)terminateExtensionCanceled:(BOOL)canceled
{
[self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXUserCancelErrorDomain" code:4201 userInfo:nil]];
}
- (void)cancelSharingWithFailure
{
[self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXFailureErrorDomain" code:500 userInfo:nil]];
if (canceled)
{
[self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXUserCancelErrorDomain" code:4201 userInfo:nil]];
}
else
{
[self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXFailureErrorDomain" code:500 userInfo:nil]];
}
}
- (UIAlertController *)compressionPromptForImage:(UIImage *)image shareBlock:(nonnull void(^)())shareBlock

View file

@ -108,7 +108,7 @@
void (^failureBlock)() = ^void() {
[self dismissViewControllerAnimated:YES completion:^{
[[ShareExtensionManager sharedManager] cancelSharingWithFailure];
[[ShareExtensionManager sharedManager] terminateExtensionCanceled:NO];
}];
};
@ -167,7 +167,7 @@
- (IBAction)close:(UIButton *)sender
{
[self dismissViewControllerAnimated:YES completion:^{
[[ShareExtensionManager sharedManager] cancelSharing];
[[ShareExtensionManager sharedManager] terminateExtensionCanceled:YES];
}];
}