Tutorial How to add toast message in your tweak

AndnixSH

PMT Elite Modder
Original poster
Staff member
Modding-Team
Jun 27, 2017
4,759
301,673
1,213
Modding World
I found a project that can display a toast message in iOS which has the same functionality as Toast in Android

Download Toast project as zip scalessec/Toast

Extract Toast folder to your tweak

In your Makefile, Add UIView+Toast.m to [PROJECTNAME]_FILES

In your tweak.xm, Include UIView+Toast.h like
C++:
#include "Toast/UIView+Toast.h"

And add your UIView variable and hook view controller like UIViewController

Objective-C:
UIView *uiView;

//Set our view variable
%hook UIViewController
  -(void)viewDidLoad {
    %orig;
    uiView = self.view;
  }
%end

If UIViewController doesn't work, try other views.

Now you can use it like:

Objective-C:
static void didFinishLaunching(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef info) {
  timer(2) {

    [uiView makeToast:@"Modded by AndnixSH\nPlatinmods.com - The gaming community"];
    load();
    });
}

void launchEvent() {
    CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), NULL, &didFinishLaunching, (CFStringRef)UIApplicationDidFinishLaunchingNotification, NULL, CFNotificationSuspensionBehaviorDrop);
}

__attribute__((constructor)) static void initialize() {
    launchEvent();
}

More example can be seen on Github. You may need to replace "self.view" with your UIView variable if you are using it within C++ side

Preview:

Image 2023 05 28 14 52 29.png
 
Last edited: