Copy Status Links to Clipboard in Twitter for iPhone

Discussion in 'iOS Jailbreak & Cydia' started by Axis, Jul 29, 2010.

  1. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    I became increasingly annoyed with the great lengths to which one had to go in order to copy to clipboard the link (twitter url) of a tweet:

    1. Swipe tweet
    2. Select the "action" (right-most) button
    3. Tap "Post Link to Tweet"
    4. Manually select and copy the url from the newly created compose screen
    5. Dismiss the compose screen

    Please Register or Log in to view images



    For my own use I wrote a simple MobileSubstrate extension to "adjust" Twitter for iPhone's user interface and functionality.

    The result:

    Please Register or Log in to view images



    As you would expect, the modified button copies to clipboard the link to the tweet, no questions asked.

    For those interested, here is the code: (I used Dustin Howett's logos preprocessor to spare me from the relatively tedious tasks of fetching classes, storing original IMPs, dynamically adding new methods, etc.) Also, because I didn't want to patch dumped headers to write my own barebones ones, I use "raw" calls to objc_msgSend, lest the compiler yell because it can't find certain methods.


    [objc]
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <objc/runtime.h>

    %hook TweetieStatusActions

    - (void)actionSheet

    Please Register or Log in to view images

    UIActionSheet *)actionSheet clickedButtonAtIndex

    Please Register or Log in to view images

    int)index {

    // call orig and return if this isn't the correct alertSheet or another button was pressed
    if ([actionSheet numberOfButtons] == 2 || index != 1) {
    %orig;
    return;
    }

    id status;
    object_getInstanceVariable(self, "status", (void **)&status);

    // if the 'copy link to tweet' button was pressed:

    NSURL *url = objc_msgSend(status, @selector(twitterURL));
    [[UIPasteboard generalPasteboard] setURL:url];

    }
    %new(v@

    Please Register or Log in to view images

    )
    - (void)willPresentActionSheet

    Please Register or Log in to view images

    UIActionSheet *)actionSheet {

    if ([actionSheet numberOfButtons] == 2)
    return;

    // grab the second button, 'post link to tweet' -- (pardon the loosely-typed object)
    UIControl *button = [objc_msgSend(actionSheet, @selector(buttons)) objectAtIndex:1];

    // setting a new title screws with the frame;
    // save the original on the stack, then set it
    CGRect orig_frame = [button frame];
    objc_msgSend(button, @selector(setTitle

    Please Register or Log in to view images

    , @"Copy Link to Tweet");
    [button setFrame

    Please Register or Log in to view images

    rig_frame];

    }
    %end

    static __attribute__((constructor))
    void init() {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    %init;

    [pool release];
    }
    [/objc]

    I made this for myself, but I figured that there are others who might find this useful. Attached is a zip containing two files, the dynamic library itself and a plist. Copy both to /Library/MobileSubstrate/DynamicLibraries on your iDevice and respring.

    Cheers.

    Attached Files:

  2. m0in

    m0in Well-Known Member

    Joined:
    Dec 28, 2009
    Messages:
    2,723
    Likes Received:
    28
    Device:
    4G iPod touch
    Wheres the zip?
  3. flyingguitar

    flyingguitar Active Member

    Joined:
    May 14, 2008
    Messages:
    1,860
    Likes Received:
    11
    Device:
    iPhone 6
    good job man, and it was especially nice of you to put the source code here for us. Well done!
  4. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    Try now.
  5. GazaIan

    GazaIan Well-Known Member

    Joined:
    May 19, 2010
    Messages:
    5,975
    Likes Received:
    431
    Device:
    Nexus 4
    Axis, i love you. thank you so much

    Please Register or Log in to view images

  6. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    I have some free time now, so post tweaks/mods you would like to see (for SpringBoard or other apps).
  7. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    After further testing, I found that my original mod was tampering with not one, but two alert sheets. I've revised the code to fix this problem, and uploaded a new zip. Install instructions remain the same.

Share This Page