Megacool
@interface Megacool : NSObject
-
Returns the singleton instance of Megacool. Must be used to call the Megacool methods.
Declaration
Objective-C
+ (nullable Megacool *)sharedMegacool;
Swift
class func shared() -> Megacool?
Return Value
nil if
startWithAppConfig
hasn’t been called yet, otherwise the singleton. -
Initializes the SDK. Get your app config from your Megacool Dashboard.
Declaration
Objective-C
+ (void)startWithAppConfig:(nonnull NSString *)appConfig;
Swift
class func start(withAppConfig appConfig: String)
Parameters
appConfig
NSString with the format
"prefix.appSecret"
-
Initializes the SDK with a callback handler for events. Get your app config from your Megacool Dashboard.
There are 3 main events to handle:
- MCLEventLinkClicked: The app was opened from a link click.
MCLEvent.type
is MCLEventLinkClicked andevent.data
contains the path, query, referralCode and full URL, to send the user to the right scene. A request is sent to the server asap, and aMCLEvent
with typereceivedShareOpened
will be passed to the callback with the associated share.
Note that if you are using any other SDKs alongside Megacool,
MCLEventLinkClicked
events might also be sent for URLs that were intended for the other SDKs. Since these events are intended for navigation within the app, you should validate that the path makes sense before routing the user to it, otherwise you can probably just ignore this event as the other SDKs will probably handle it.MCLEventReceivedShareOpened: When a shared link is clicked to either open or install the app, the eventHandler will receive the
MCLEvent
from the server. TheMCLEvent.type
isMCLEventReceivedShareOpened
.isFirstSession
is a boolean telling if the app was opened for the first time (new install) or just opened. TheMCLShare
is the object that was sent to this user.MCLEventSentShareOpened: When a shared link is clicked by another user and the app opens, a
MCLEvent
will be triggered. Theevent.type
isMCLEventSentShareOpened
, and the event contains the share object that was sent from this user. It also indicates if it was a first session and theevent.data
contains the other users referral codeMCLEventDataReceiverReferralCode
so you can match the users on your own.
Declaration
Objective-C
+ (void)startWithAppConfig:(nonnull NSString *)appConfig andEventHandler:(nullable MCLEventHandlerCallback)callback;
Swift
class func start(withAppConfig appConfig: String, andEventHandler callback: MCLEventHandlerCallback? = nil)
- MCLEventLinkClicked: The app was opened from a link click.
-
Initializer dedicated for wrappers.
There are 3 main events to handle:
- MCLEventLinkClicked: The app was opened from a link click.
MCLEvent.type
is MCLEventLinkClicked andevent.data
contains the path, query, referralCode and full URL, to send the user to the right scene. A request is sent to the server asap, and aMCLEvent
with typereceivedShareOpened
will be passed to the callback with the associated share.
Note that if you are using any other SDKs alongside Megacool,
MCLEventLinkClicked
events might also be sent for URLs that were intended for the other SDKs. Since these events are intended for navigation within the app, you should validate that the path makes sense before routing the user to it, otherwise you can probably just ignore this event as the other SDKs will probably handle it.MCLEventReceivedShareOpened: When a shared link is clicked to either open or install the app, the eventHandler will receive the
MCLEvent
from the server. TheMCLEvent.type
is MCLEventReceivedShareOpened.isFirstSession
is a boolean telling if the app was opened for the first time (new install) or just opened. TheMCLShare
is the object that was sent to this user.MCLEventSentShareOpened: When a shared link is clicked by another user and the app opens, a
MCLEvent
will be triggered. Theevent.type
isMCLEventSentShareOpened
, and the event contains the share object that was sent from this user. It also indicates if it was a first session and theevent.data
contains the other users referral codeMCLEventDataReceiverReferralCode
so you can match the users on your own.
Declaration
Objective-C
+ (void)startWithAppConfig:(nonnull NSString *)appConfig wrapper:(nullable NSString *)wrapper wrapperVersion:(nullable NSString *)wrapperVersion andEventHandler:(nullable MCLEventHandlerCallback)callback;
Swift
class func start(withAppConfig appConfig: String, wrapper: String?, wrapperVersion: String?, andEventHandler callback: MCLEventHandlerCallback? = nil)
Parameters
appConfig
NSString with the format
@"prefix.appSecret"
wrapper
The name of the wrapper, ie.
Unity
orCocos2dx
. This helps us identify issues in different wrappers and versions.wrapperVersion
The version of the wrapper, ie. for Unity this could be
2018.2
5.6
.callback
- MCLEventLinkClicked: The app was opened from a link click.
-
Handle background upload/download tasks
This is necessary to properly handle uploading of gifs in the background, and to download new fallback images defined through the dashboard.
Declaration
Objective-C
+ (BOOL)handleEventsForBackgroundURLSession:(nonnull NSString *)identifier completionHandler: (nonnull void (^)(void))completionHandler;
Swift
class func handleEvents(forBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) -> Bool
Return Value
Whether we handled the events for the given identifier or whether it should be passed on to another handler.
-
Extract the URL from a link click. Add to
application:openURL:options:
in AppDelegateAdd this to
- application:openURL:options:
in your AppDelegate. If the URL was a Megacool URL, the event handler will be called with aMCLEventLinkClicked
event.Declaration
Objective-C
- (BOOL)openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<NSString *, id> *)options;
Swift
func open(_ url: URL, options: [String : Any] = [:]) -> Bool
Parameters
url
The url that was clicked. Megacool URLs will be either https://mgcl.co/youridentifer/some/path=?_m=
or yourscheme:///some/path?_m= . options
A dictionary of URL handling options.
-
Extract the URL from a link click. Add to
application:openURL:sourceApplication:
in AppDelegate if you support versions below iOS 9Add this to
- application:openURL:options:
in your AppDelegate. If the URL was a Megacool URL, the event handler will be called with aMCLEventLinkClicked
event.Declaration
Objective-C
- (BOOL)openURL:(nonnull NSURL *)url sourceApplication:(nullable NSString *)sourceApplication;
Swift
func open(_ url: URL, sourceApplication: String?) -> Bool
Parameters
url
The url that was clicked. Megacool URLs will be either https://mgcl.co/youridentifer/some/path=?_m=
or yourscheme:///some/path?_m= . sourceApplication
The
bundleId
of the sending application. -
Allow Megacool to handle a universal link opening the app, returning whether it was from a Megacool link or not. Add this to
- application:continueUserActivity:restorationHandler:
in your AppDelegate.Declaration
Objective-C
+ (BOOL)continueUserActivity:(nonnull NSUserActivity *)userActivity;
Swift
class func `continue`(_ userActivity: NSUserActivity) -> Bool
Parameters
userActivity
that caused the app to open.
-
Start recording a GIF from a view.
This will keep a buffer of 50 frames (default). The frames are overwritten until
stopRecording
gets called.Declaration
Objective-C
- (void)startRecording:(nonnull UIView *)view;
Swift
func startRecording(_ view: UIView)
Parameters
view
UIView you want to record
-
Start customized GIF recording
This will keep a buffer of 50 frames (default). The frames are overwritten until
stopRecording
gets called.Declaration
Objective-C
- (void)startRecording:(nonnull UIView *)view withConfig:(nullable MCLRecordingConfigBlock)configBlock;
Swift
func startRecording(_ view: UIView, withConfig configBlock: MCLRecordingConfigBlock? = nil)
Parameters
view
UIView you want to record
configBlock
MCLRecordingConfigBlock to customize the recording.
-
Capture a single frame
Capture a single frame of the UIView to the buffer. The buffer size is 50 frames (default) and the oldest frames will be deleted if the method gets called more than 50 times. The total number of frames can be customized by setting the
maxFrames
property on thesharedMegacool
instance. If you want a different strategy for handling too many frames, look atkMCLOverflowStrategyTimelapse
.Declaration
Objective-C
- (void)captureFrame:(nonnull UIView *)view;
Swift
func captureFrame(_ view: UIView)
Parameters
view
UIView you want to capture a frame from
-
Declaration
Objective-C
- (void)captureFrame:(nonnull UIView *)view withConfig:(nullable MCLRecordingConfigBlock)configBlock;
Swift
func captureFrame(_ view: UIView, withConfig configBlock: MCLRecordingConfigBlock? = nil)
-
Declaration
Objective-C
- (void)captureFrame:(nonnull UIView *)view withConfig:(nullable MCLRecordingConfigBlock)configBlock forceAdd:(BOOL)force;
Swift
func captureFrame(_ view: UIView, withConfig configBlock: MCLRecordingConfigBlock?, forceAdd force: Bool)
-
Pauses the current recording for resumption later.
The frames captured so far will be stored on disk and can be resumed later by calling
startRecording
/captureFrame
with the same"recordingId"
.Declaration
Objective-C
- (void)pauseRecording;
Swift
func pauseRecording()
-
Stop recording the UIView set in startRecording.
This method should be called after
startRecording
orcaptureFrame
to mark the recording as completed. A completed recording can not have any more frames added to it, callingcaptureFrame
orstartRecording
with the samerecordingId
as a completed recording will overwrite the old one.Declaration
Objective-C
- (void)stopRecording;
Swift
func stopRecording()
-
Delete a recording.
Will remove any frames of the recording in memory and on disk. Both completed and incomplete recordings will take space on disk, thus particularly if you’re using
keepCompletedRecordings=YES
you might want to provide an interface to your users for removing recordings they don’t care about anymore to free up space for new recordings.Declaration
Objective-C
- (void)deleteRecording:(nullable NSString *)recordingId;
Swift
func deleteRecording(_ recordingId: String?)
Parameters
recordingId
the id of the recording to delete, or nil to delete the default.
-
Log a significant event for highlightRecording
For highlight recording strategy only. This will make note of the time that a significant event occurs so that highlight recording can select the most interesting part of the gameplay
Declaration
Objective-C
- (void)registerScoreChange;
Swift
func registerScoreChange()
-
Log a the change in point value for highlightRecording
For highlight recording strategy only. This will make note of the time that a significant event occurs along with the point value associated with it so that highlight recording can select the most interesting part of the gameplay
Declaration
Objective-C
- (void)registerScoreChange:(int)scoreDelta;
Swift
func registerScoreChange(_ scoreDelta: Int32)
Parameters
scoreDelta
the change in point value
-
Get the number of frames in the current recording
This method is used to know if frames exist in the current recording, before showing a preview or displaying a share button.
Declaration
Objective-C
- (int)getNumberOfFrames;
Swift
func getNumberOfFrames() -> Int32
-
Get the number of frames from a specific recording
This method is used to know if frames exist in the current recording, before showing a preview or displaying a share button.
Declaration
Objective-C
- (int)getNumberOfFrames:(nullable NSString *)recordingId;
Swift
func getNumberOfFrames(_ recordingId: String?) -> Int32
Parameters
recordingId
to get the number of frames from a specific recording, or nil to get for the default recording
-
Get the currently active capture method.
Declaration
Objective-C
- (MCLCaptureMethod)captureMethod;
Swift
func captureMethod() -> MCLCaptureMethod
-
Set how screen captures should be performed, using the default scale factor. Call this as soon as possible after start. Calling this more than once leads to undefined behavior.
Note
This ia a low-level API that’s usually not neeed.
Declaration
Objective-C
- (void)setCaptureMethod:(MCLCaptureMethod)captureMethod;
Swift
func setCaptureMethod(_ captureMethod: MCLCaptureMethod)
Parameters
captureMethod
capture method to use for recording
-
Set how screen captures should be performed, using the default scale factor. Call this as soon as possible after start. Calling this more than once leads to undefined behavior.
The default scale factor is 0.5 for screens whose longest side is < 1500 in length, or 0.25 for anything larger. If the resulting dimensions are less than 200 for either width or height, then the scale factor is increased to ensure a minimum of 200 or more in both dimensions. By passing in a value for ScaleFactor, you override this behavior. It’s important to keep in mind that while a larger scale factor will produce encoded media with a higher resolution, it will make captures and encoding slower, and also increase the size of the encoded media, which will increase both disk and network usage. In any case, we will round up the scaled dimensions to be divisible by 16, as this is a requirement for many MP4 encoders.
Note
This ia a low-level API that’s usually not neeed.
Declaration
Objective-C
- (void)setCaptureMethod:(MCLCaptureMethod)captureMethod withScaleFactor:(double)scaleFactor;
Swift
func setCaptureMethod(_ captureMethod: MCLCaptureMethod, withScaleFactor scaleFactor: Double)
Parameters
captureMethod
capture method to use for recording
scaleFactor
a custom scale factor to use for encoding recordings
-
Wrapper for mcl_init_render_thread. Used by custom engines.
Note
Must be called on the render thread.Declaration
Objective-C
- (void)initRenderThread;
Swift
func initRenderThread()
-
Wrapper for mcl_notify_render_complete. Used by custom engines.
Declaration
Objective-C
- (void)notifyRenderComplete;
Swift
func notifyRenderComplete()
-
Get a view that previews the default recording.
Call
startAnimating
on the returnedMCLPreview
to start the animation. UsegetPreviewWithConfig
to customize which recording to preview, or set where the view should appear. You can also set theframe
on the returned view to position it.Return Value
MCLPreview for the default recording.
-
Render preview of GIF with a given frame size that can be showed before sharing.
Call
startAnimating
on the returnedMCLPreview
to start the animation.Declaration
Objective-C
- (nullable MCLPreview *)getPreviewWithConfig: (nullable MCLPreviewConfigBlock)configBlock;
Swift
func getPreviewWithConfig(_ configBlock: MCLPreviewConfigBlock? = nil) -> MCLPreview?
Parameters
configBlock
Configuration block to configure the preview.
Return Value
MCLPreview for the GIF specified in
config.recordingId
, or the default if not given. Will returnnil
if the requested recording has zero frames or does not exist. -
Get the data needed to build your own preview. This is a low-level interface intended for custom engines, you’re probably better of using the getPreview/getPreviewWithConfig methods.
Declaration
Objective-C
- (nonnull MCLPreviewData *)getPreviewDataForRecording: (nullable NSString *)recordingId;
Swift
func getPreviewData(forRecording recordingId: String?) -> MCLPreviewData
Parameters
recordingId
which recording to get preview data for, or null for the default.
Return Value
MCLPreviewData for the given recording, or null if there’s no such recording.
-
Present the default share modal view in a view controller
Shows a native share modal view with supported sharing channels like SMS, Twitter, Facebook etc.
Note
This method must be called from the main thread of your application.On some devices this might block for some time, to prevent user frustration we recommend showing a spinner and calling this method from a selector with [self performSelector:withObject:afterDelay:], using a delay of .1 (otherwise some devices won’t show the spinner at all before blocking). You should then stop and remove the spinner once this method returns. Example:
- (void)share { [self.view addSubview:self.spinner]; [self.spinner startAnimating]; self.spinner.center = self.view.center; [self performSelector:@selector(shareAfterSpinner) withObject:nil afterDelay:.1]; } - (void)shareAfterSpinner { [[Megacool sharedMegacool] presentShare]; [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; }
Declaration
Objective-C
- (void)presentShare;
Swift
func presentShare()
-
Present the default share modal view in a view controller
Shows a native share modal view with supported sharing channels like SMS, Twitter, Facebook etc.
Note
This method must be called from the main thread of your application.
On some devices this might block for some time, to prevent user frustration we recommend showing a spinner and calling this method from a selector with [self performSelector:withObject:afterDelay:], using a delay of .1 (otherwise some devices won’t show the spinner at all before blocking). You should then stop and remove the spinner once this method returns. Example:
- (void)share { [self.view addSubview:self.spinner]; [self.spinner startAnimating]; self.spinner.center = self.view.center; [self performSelector:@selector(shareAfterSpinner) withObject:nil afterDelay:.1]; } - (void)shareAfterSpinner { [[Megacool sharedMegacool] presentShareWithConfig:^(MCLShareConfig *config) { config.recordingId = @"level1"; }]; [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; }
Declaration
Objective-C
- (void)presentShareWithConfig:(nullable MCLShareConfigBlock)configBlock;
Swift
func presentShare(config configBlock: MCLShareConfigBlock? = nil)
Parameters
configBlock
configures how the share is performed.
-
Present the default share modal view in a view controller
Shows a native share modal view with supported sharing channels like SMS, Twitter, Facebook etc.
Note
This method must be called from the main thread of your application.
On some devices this might block for some time, to prevent user frustration we recommend showing a spinner and calling this method from a selector with [self performSelector:withObject:afterDelay:], using a delay of .1 (otherwise some devices won’t show the spinner at all before blocking). You should then stop and remove the spinner once this method returns. Example:
- (void)share { [self.view addSubview:self.spinner]; [self.spinner startAnimating]; self.spinner.center = self.view.center; [self performSelector:@selector(shareAfterSpinner) withObject:nil afterDelay:.1]; } - (void)shareAfterSpinner { [[Megacool sharedMegacool] presentShareWithConfig:^(MCLShareConfig *config) { config.recordingId = @"level1"; } inViewController:self]; [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; }
Declaration
Objective-C
- (void)presentShareWithConfig:(nullable MCLShareConfigBlock)configBlock inViewController:(nullable UIViewController *)viewController;
Swift
func presentShare(config configBlock: MCLShareConfigBlock?, in viewController: UIViewController?)
Parameters
configBlock
configures how the share is performed.
viewController
The view controller that will present the share modal view
-
Present Twitter share
This opens the Twitter app if it’s installed, with a predefined tweet consisting of the sharing text and link. The GIF is copied to the pasteboard so the user can paste it in the tweet. The user will get a notification that teaches how to paste it. If the Twitter app is not installed, a notification will tell the user to install it.
Note
This method must be called from the main thread of your application.On some devices this might block for some time, to prevent user frustration we recommend showing a spinner and calling this method from a selector with [self performSelector:withObject:afterDelay:], using a delay of .1 (otherwise some devices won’t show the spinner at all before blocking). You should then stop and remove the spinner once this method returns. Example:
- (void)share { [self.view addSubview:self.spinner]; [self.spinner startAnimating]; self.spinner.center = self.view.center; [self performSelector:@selector(shareAfterSpinner) withObject:nil afterDelay:.1]; } - (void)shareAfterSpinner { [[Megacool sharedMegacool] presentShareToTwitter]; [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; }
Declaration
Objective-C
- (void)presentShareToTwitter;
Swift
func presentShareToTwitter()
-
Present Twitter share
This opens the Twitter app if it’s installed, with a predefined tweet consisting of the sharing text and link. The GIF is copied to the pasteboard so the user can paste it in the tweet. The user will get a notification that teaches how to paste it. If the Twitter app is not installed, a notification will tell the user to install it.
Note
This method must be called from the main thread of your application.
On some devices this might block for some time, to prevent user frustration we recommend showing a spinner and calling this method from a selector with [self performSelector:withObject:afterDelay:], using a delay of .1 (otherwise some devices won’t show the spinner at all before blocking). You should then stop and remove the spinner once this method returns. Example:
- (void)share { [self.view addSubview:self.spinner]; [self.spinner startAnimating]; self.spinner.center = self.view.center; [self performSelector:@selector(shareAfterSpinner) withObject:nil afterDelay:.1]; } - (void)shareAfterSpinner { [[Megacool sharedMegacool] presentShareToTwitterWithConfig:^(MCLShareConfig *config) { config.recordingId = @"level1"; }]; [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; }
Declaration
Objective-C
- (void)presentShareToTwitterWithConfig: (nullable MCLShareConfigBlock)configBlock;
Swift
func presentShareToTwitter(config configBlock: MCLShareConfigBlock? = nil)
Parameters
configBlock
configures how the share is performed.
-
Present Messenger share view
Presents a Messenger share view where the user can compose a message that includes a link to your app and the recorded GIF.
Note
This method must be called from the main thread of your application.On some devices this might block for some time, to prevent user frustration we recommend showing a spinner and calling this method from a selector with [self performSelector:withObject:afterDelay:], using a delay of .1 (otherwise some devices won’t show the spinner at all before blocking). You should then stop and remove the spinner once this method returns. Example:
- (void)share { [self.view addSubview:self.spinner]; [self.spinner startAnimating]; self.spinner.center = self.view.center; [self performSelector:@selector(shareAfterSpinner) withObject:nil afterDelay:.1]; } - (void)shareAfterSpinner { [[Megacool sharedMegacool] presentShareToMessenger]; [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; }
Declaration
Objective-C
- (void)presentShareToMessenger;
Swift
func presentShareToMessenger()
-
Present Messenger share view
Presents a Messenger share view where the user can compose a message that includes a link to your app and the recorded GIF.
Note
This method must be called from the main thread of your application.
On some devices this might block for some time, to prevent user frustration we recommend showing a spinner and calling this method from a selector with [self performSelector:withObject:afterDelay:], using a delay of .1 (otherwise some devices won’t show the spinner at all before blocking). You should then stop and remove the spinner once this method returns. Example:
- (void)share { [self.view addSubview:self.spinner]; [self.spinner startAnimating]; self.spinner.center = self.view.center; [self performSelector:@selector(shareAfterSpinner) withObject:nil afterDelay:.1]; } - (void)shareAfterSpinner { [[Megacool sharedMegacool] presentShareToMessengerWithConfig:^(MCLShareConfig *config) { config.recordingId = @"level1"; }]; [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; }
Declaration
Objective-C
- (void)presentShareToMessengerWithConfig: (nullable MCLShareConfigBlock)configBlock;
Swift
func presentShareToMessenger(config configBlock: MCLShareConfigBlock? = nil)
Parameters
configBlock
configures how the share is performed.
-
Present a native iMessage share view
Note
This method must be called from the main thread of your application.On some devices this might block for some time, to prevent user frustration we recommend showing a spinner and calling this method from a selector with [self performSelector:withObject:afterDelay:], using a delay of .1 (otherwise some devices won’t show the spinner at all before blocking). You should then stop and remove the spinner once this method returns. Example:
- (void)share { [self.view addSubview:self.spinner]; [self.spinner startAnimating]; self.spinner.center = self.view.center; [self performSelector:@selector(shareAfterSpinner) withObject:nil afterDelay:.1]; } - (void)shareAfterSpinner { [[Megacool sharedMegacool] presentShareToMessages]; [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; }
Declaration
Objective-C
- (void)presentShareToMessages;
Swift
func presentShareToMessages()
-
Present a native iMessage share view
Note
This method must be called from the main thread of your application.
On some devices this might block for some time, to prevent user frustration we recommend showing a spinner and calling this method from a selector with [self performSelector:withObject:afterDelay:], using a delay of .1 (otherwise some devices won’t show the spinner at all before blocking). You should then stop and remove the spinner once this method returns. Example:
- (void)share { [self.view addSubview:self.spinner]; [self.spinner startAnimating]; self.spinner.center = self.view.center; [self performSelector:@selector(shareAfterSpinner) withObject:nil afterDelay:.1]; } - (void)shareAfterSpinner { [[Megacool sharedMegacool] presentShareToMessagesWithConfig:^(MCLShareConfig *config) { config.recordingId = @"level1"; }]; [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; }
Declaration
Objective-C
- (void)presentShareToMessagesWithConfig: (nullable MCLShareConfigBlock)configBlock;
Swift
func presentShareToMessages(config configBlock: MCLShareConfigBlock? = nil)
Parameters
configBlock
configures how the share is performed.
-
Present a native iMessage share view
Note
This method must be called from the main thread of your application.
On some devices this might block for some time, to prevent user frustration we recommend showing a spinner and calling this method from a selector with [self performSelector:withObject:afterDelay:], using a delay of .1 (otherwise some devices won’t show the spinner at all before blocking). You should then stop and remove the spinner once this method returns. Example:
- (void)share { [self.view addSubview:self.spinner]; [self.spinner startAnimating]; self.spinner.center = self.view.center; [self performSelector:@selector(shareAfterSpinner) withObject:nil afterDelay:.1]; } - (void)shareAfterSpinner { [[Megacool sharedMegacool] presentShareToMessagesWithConfig:^(MCLShareConfig *config) { config.recordingId = @"level1"; } inViewController:self]; [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; }
Declaration
Objective-C
- (void) presentShareToMessagesWithConfig:(nullable MCLShareConfigBlock)configBlock inViewController:(nullable UIViewController *)viewController;
Swift
func presentShareToMessages(config configBlock: MCLShareConfigBlock?, in viewController: UIViewController?)
Parameters
configBlock
configures how the share is performed.
viewController
The view controller that will present the iMessage view
-
Present a native Mail share view
Note
This method must be called from the main thread of your application.On some devices this might block for some time, to prevent user frustration we recommend showing a spinner and calling this method from a selector with [self performSelector:withObject:afterDelay:], using a delay of .1 (otherwise some devices won’t show the spinner at all before blocking). You should then stop and remove the spinner once this method returns. Example:
- (void)share { [self.view addSubview:self.spinner]; [self.spinner startAnimating]; self.spinner.center = self.view.center; [self performSelector:@selector(shareAfterSpinner) withObject:nil afterDelay:.1]; } - (void)shareAfterSpinner { [[Megacool sharedMegacool] presentShareToMail]; [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; }
Declaration
Objective-C
- (void)presentShareToMail;
Swift
func presentShareToMail()
-
Present a native Mail share view
Note
This method must be called from the main thread of your application.
On some devices this might block for some time, to prevent user frustration we recommend showing a spinner and calling this method from a selector with [self performSelector:withObject:afterDelay:], using a delay of .1 (otherwise some devices won’t show the spinner at all before blocking). You should then stop and remove the spinner once this method returns. Example:
- (void)share { [self.view addSubview:self.spinner]; [self.spinner startAnimating]; self.spinner.center = self.view.center; [self performSelector:@selector(shareAfterSpinner) withObject:nil afterDelay:.1]; } - (void)shareAfterSpinner { [[Megacool sharedMegacool] presentShareToMailWithConfig:^(MCLShareConfig *config) { config.recordingId = @"level1"; }]; [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; }
Declaration
Objective-C
- (void)presentShareToMailWithConfig:(nullable MCLShareConfigBlock)configBlock;
Swift
func presentShareToMail(config configBlock: MCLShareConfigBlock? = nil)
Parameters
configBlock
configures how the share is performed.
-
Present a native Mail share view
Note
This method must be called from the main thread of your application.
On some devices this might block for some time, to prevent user frustration we recommend showing a spinner and calling this method from a selector with [self performSelector:withObject:afterDelay:], using a delay of .1 (otherwise some devices won’t show the spinner at all before blocking). You should then stop and remove the spinner once this method returns. Example:
- (void)share { [self.view addSubview:self.spinner]; [self.spinner startAnimating]; self.spinner.center = self.view.center; [self performSelector:@selector(shareAfterSpinner) withObject:nil afterDelay:.1]; } - (void)shareAfterSpinner { [[Megacool sharedMegacool] presentShareToMailWithConfig:^(MCLShareConfig *config) { config.recordingId = @"level1"; } inViewController:self]; [self.spinner stopAnimating]; [self.spinner removeFromSuperview]; }
Declaration
Objective-C
- (void)presentShareToMailWithConfig:(nullable MCLShareConfigBlock)configBlock inViewController: (nullable UIViewController *)viewController;
Swift
func presentShareToMail(config configBlock: MCLShareConfigBlock?, in viewController: UIViewController?)
Parameters
configBlock
configures how the share is performed.
viewController
The view controller that will present the Mail share view
-
Get the shares sent by the user.
The locally cached shares will be returned immediately and are useful for determining how many shares have been sent and when that was done. If the callback is non-nil we will query the backend for an updated status on the shares to see if anything has happened since last time.
Each element in the list returned will be a
MCLShare
(link to docs).Declaration
Objective-C
- (nonnull NSArray<MCLShare *> *)getShares: (nullable MCLShareStateCallback)callback;
Swift
func getShares(_ callback: MCLShareStateCallback? = nil) -> [MCLShare]
-
Get the shares sent by the user, with filtering.
Use this instead of
-getShares:
when you only want a subset of the shares, to keep network traffic to a minimum. The locally cached shares will be returned immediately and are useful for determining how many shares have been sent and when that was done. If the callback is non-nil we will query the backend for an updated status on the shares to see if anything has happened since last time.Each element in the list returned will be a
MCLShare
(link to docs).Declaration
Objective-C
- (nonnull NSArray<MCLShare *> *) getShares:(nullable MCLShareStateCallback)callback withFilter:(nullable MCLShareFilterCallback)filter;
Swift
func getShares(_ callback: MCLShareStateCallback?, withFilter filter: MCLShareFilterCallback? = nil) -> [MCLShare]
Parameters
filter
can be used to filter out the shares returned. An example is to only return those who haven’t yet generated an install. The filter loops through all shares and you can decide for each share if it should be fetched or not by returning YES / NO.
-
Delete local share objects
Local shares are also useful to show the users how many shares they’ve sent and what their statuses are. But at a certain time you might want to delete old ones.
Declaration
Objective-C
- (void)deleteSharesMatchingFilterFromDevice: (nullable MCLShareFilterCallback)filter;
Swift
func deleteSharesMatchingFilter(fromDevice filter: MCLShareFilterCallback? = nil)
Parameters
filter
is used to delete old share objects you don’t want local anymore. I.e. shares that have been installed and are over 2 days old can be deleted. For each share, return
YES/NO
if it should be deleted. -
Get the inviter id for this user/app.
The inviter id will be passed to the callback immediately if known, otherwise the callback will be called when we’ve received the inviter id from the backend, which happens on the first session, and will be stored locally after that.
Declaration
Objective-C
- (void)getUserId:(nonnull MCLReferralCodeCallback)callback;
Swift
func getUserId(_ callback: @escaping MCLReferralCodeCallback)
-
Set the default share config. This will be merged with the config given to
presentShareWithConfig:
, if any.Set to nil to reset.
Declaration
Objective-C
@property (readwrite, strong, nonatomic, null_resettable) MCLShareConfig *defaultShareConfig;
Swift
var defaultShareConfig: MCLShareConfig! { get set }
-
The default recording config. This will be merged with the config given to
startRecording:withConfig
orcaptureFrame:withConfig
, if any.Note that the config is mutable, but changes made to the default config after a call to startRecording or captureFrame will have no effect until the next recording is started.
Set to nil to reset.
Declaration
Objective-C
@property (readwrite, strong, nonatomic, null_resettable) MCLRecordingConfig *defaultRecordingConfig;
Swift
var defaultRecordingConfig: MCLRecordingConfig! { get set }
-
Assign the delegate for callbacks
Declaration
Objective-C
@property (readwrite, nonatomic, nullable) id<MCLDelegate> delegate;
Swift
weak var delegate: MCLDelegate? { get set }
-
Set the type of GIF color table to use. The default is
kMCLGIFColorTableDynamic
.The resulting GIF can only hold 256 different colors, this property determines how those colors are selected.
This only has any effect when sharing to apps where .gif gives a better experience than .mp4. Try sharing to email or messages to see the impact of this.
Declaration
Objective-C
@property (assign, readwrite, nonatomic) MCLGIFColorTable gifColorTable;
Swift
var gifColorTable: MCLGIFColorTable { get set }
-
Set which Metal texture to capture from.
Declaration
Objective-C
@property (readwrite, strong, nonatomic, nullable) id<MTLTexture> metalCaptureTexture;
Swift
var metalCaptureTexture: MTLTexture? { get set }
-
Whether to keep completed recordings around.
The default is
NO
, which means that all completed recordings will be deleted whenever a new recording is started with eithercaptureFrame
orstartRecording
. Setting this toYES
means we will never delete a completed recording, which is what you want if you want to enable players to browse previous GIFs they’ve created. A completed recording will still be overwritten if a new recording is started with the samerecordingId.
Declaration
Objective-C
@property (assign, readwrite, nonatomic) BOOL keepCompletedRecordings;
Swift
var keepCompletedRecordings: Bool { get set }
-
Turn on / off debug mode. In debug mode calls to the SDK are stored and can be submitted to the core developers using
submitDebugDataWithMessage
later.Declaration
Objective-C
+ (void)setDebug:(BOOL)debug;
Swift
class func setDebug(_ debug: Bool)
-
Get whether debugging is currently enabled or not.
Declaration
Objective-C
+ (BOOL)debug;
Swift
class func debug() -> Bool
-
Disable a set of features
If something fails or is not desired on a class of devices, some features can be disabled remotely through the dashboard. To be able to test behavior when this is the case, or to always force a given feature to be disabled, you can call this function with a list of the features you want to disable.
Features disabled through this call will not be visible or configurable through the dashboard. A feature will be disabled if it’s disabled either through this call or remotely or both. This call will overwrite any effects of previous calls, thus calling
disableFeatures:kMCLFeatureGifs
followed bydisableFeatures:kMCLFeatureAnalytics
would leave only analytics disabled. Combine features with the bitwise OR operator|
to disable multiple features, likedisableFeatures:kMCLFeatureAnalytics|kMCLFeatureGifUpload
.The supported features you can disable is:
- GIFs: Disable all recording, frame capturing and subsequent creation of the GIF. Available
as the constant
kMCLFeatureGifs.
- GIF uploading: By default all GIFs created are uploaded to our servers, which is
necessaryto be able to share GIFs to Facebook and Twitter, and for you to see them in the
dashboard. This does have some networking overhead though, so if you’re very constrained in terms
of bandwidth you can disable this. Include the constant
kMCLFeatureGifUpload.
- Analytics: To be able to determine whether an install or an app open event came from a
link we have to submit some events to our servers to be able to match the event to a link click
detected by us. If you are very concerned about
your user’s privacy or don’t want to incur the extra networking required, you can disable this
feature. Note that users will not be credited for inviting friends if this feature is off. Include
the constant
kMCLFeatureAnalytics.
Declaration
Objective-C
- (void)disableFeatures:(MCLFeature)features;
Swift
func disableFeatures(_ features: MCLFeature)
- GIFs: Disable all recording, frame capturing and subsequent creation of the GIF. Available
as the constant
-
Submit debug data to the core developers along with a message explaining the expected outcome and what was observed instead.
Remember to set
Megacool.debug = YES;
on startup if you intend to use this call, otherwise the report will nots contain call traces and it’ll be harder to reproduce your issue.Declaration
Objective-C
- (void)submitDebugDataWithMessage:(nonnull NSString *)message;
Swift
func submitDebugData(withMessage message: String)
-
Resets the device identity, enabling it to receive events with
isFirstSession
=YES again.Use this if you’re testing the invite flow and you want to wipe previous data from the device. This will issue your device a new identity, which means it can receive
recievedShareOpened
events again withisFirstSession
set toYES
, and enabling you to click previous links sent by the same device, mitigating the need for multiple devices to test invites.This method should be called before
-startWithAppConfig:
, otherwise the changes will not have any effect until the next session.Declaration
Objective-C
+ (void)resetIdentity;
Swift
class func resetIdentity()