Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Preliminary iOS 8 Support
Browse files Browse the repository at this point in the history
a bug involving the text field still needs fixing
  • Loading branch information
张国晔 committed Nov 16, 2014
1 parent 32136df commit db57ef9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARCHS = armv7 armv7s arm64
TARGET = iphone:clang:7.1:7.0
TARGET = iphone:clang:8.1:7.0

include theos/makefiles/common.mk

Expand Down
26 changes: 23 additions & 3 deletions Tweak.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,34 @@

#import <MessageUI/MessageUI.h>

@protocol CKMessage
@protocol CKMessage // iOS 7
@property(readonly, nonatomic) BOOL isOutgoing;
@property(readonly, nonatomic) BOOL isiMessage;
@property(readonly, nonatomic) NSDate *date;
@property(readonly, nonatomic) NSString *address;
@end

@interface IMHandle // iOS 8
@property(readonly, nonatomic) NSString *ID;
@end

@interface IMMessage // iOS 8
@property(readonly, nonatomic) BOOL __ck_isiMessage;
@property(readonly, nonatomic) BOOL isFromMe;
@property(readonly, nonatomic) NSDate *time;
@property(readonly, nonatomic) IMHandle *sender;
@end

@interface CKMessagePartChatItem // iOS 8
@property(readonly, nonatomic) IMMessage *message;
@end

@interface CKTranscriptCollectionViewController : UIViewController <MFMailComposeViewControllerDelegate>
- (id<CKMessage>)messageForBalloonView:(id)view;
- (BOOL)shouldShowReportForMessage:(id<CKMessage>)message;
- (id<CKMessage>)messageForBalloonView:(id)view; // iOS 7
- (CKMessagePartChatItem *)messagePartForBalloonView:(id)view; // iOS 8
- (void)balloonView:(id)view report:(id)sender; // iOS 8
@end

@interface CKBalloonView // iOS 8
@property(nonatomic) CKTranscriptCollectionViewController *delegate;
@end
78 changes: 43 additions & 35 deletions Tweak.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
%hook CKTranscriptCollectionViewController

- (NSArray *)menuItemsForBalloonView:(id)view {
if ([self shouldShowReportForMessage:[self messageForBalloonView:view]]) {
NSMutableArray *menuItems = [%orig(view) mutableCopy];
BOOL shouldShow;
if ([self respondsToSelector:@selector(messageForBalloonView:)]) {
id<CKMessage> message = [self messageForBalloonView:view];
shouldShow = message.isiMessage && !message.isOutgoing;
} else {
IMMessage *message = [self messagePartForBalloonView:view].message;
shouldShow = message.__ck_isiMessage && !message.isFromMe;
}
if (shouldShow) {
NSMutableArray *menuItems = [%orig mutableCopy];
NSString *title = @{REPORT_DICT}[[[NSLocale preferredLanguages] objectAtIndex:0]];
if (!title)
title = REPORT_DEFAULT;
UIMenuItem *report = [[UIMenuItem alloc] initWithTitle:title action:@selector(report:)];
[menuItems addObject:report];
return menuItems;
} else
return %orig(view);
return %orig;
}

%new
Expand All @@ -22,52 +30,42 @@ - (void)balloonView:(id)view report:(id)sender {
token = nil;
MFMailComposeViewController *mc = [MFMailComposeViewController new];
if (mc) {
UIImage *_UICreateScreenUIImage();
UIImage *image = _UICreateScreenUIImage();
UIInterfaceOrientation orientation = self.interfaceOrientation;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && orientation != UIInterfaceOrientationLandscapeLeft) {
CGSize size = image.size;
UIImageOrientation rotate;
CGFloat height, width;
if (orientation == UIInterfaceOrientationLandscapeRight) {
rotate = UIImageOrientationDown;
height = size.height;
width = size.width;
} else {
height = size.width;
width = size.height;
if (orientation == UIInterfaceOrientationPortrait)
rotate = UIImageOrientationLeft;
else
rotate = UIImageOrientationRight;
}
UIGraphicsBeginImageContext(CGSizeMake(height, width));
[[UIImage imageWithCGImage:[image CGImage] scale:1.0 orientation:rotate] drawInRect:CGRectMake(0 ,0 ,height ,width)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
UIWindow *window = self.view.window;
UIView *view = [[UIApplication sharedApplication] valueForKey:@"_statusBarWindow"];
UIGraphicsBeginImageContext(view.bounds.size);
[window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *screenshot = UIImagePNGRepresentation(image);

NSDate *date;
NSString *address;
if ([self respondsToSelector:@selector(messageForBalloonView:)]) {
id<CKMessage> message = [self messageForBalloonView:view];
date = message.date;
address = message.address;
} else {
IMMessage *message = [self messagePartForBalloonView:view].message;
date = message.time;
address = message.sender.ID;
}

mc.mailComposeDelegate = self;
[mc setSubject:@"Spam Report"];
id<CKMessage> message = [self messageForBalloonView:view];
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:@"yyyy'-'MM'-'dd' 'HH':'mm' 'z"];
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
[mc setMessageBody:[NSString stringWithFormat:@"%@\n%@", message.address, [dateFormatter stringFromDate:message.date]] isHTML:NO];
[mc setMessageBody:[NSString stringWithFormat:@"%@\n%@", address, [dateFormatter stringFromDate:date]] isHTML:NO];
[mc setToRecipients:@[@"imessage.spam@icloud.com"]];
[mc addAttachmentData:screenshot mimeType:@"image/png" fileName:@"screenshot.png"];
[self presentViewController:mc animated:YES completion:nil];
}
}];
}

%new
- (BOOL)shouldShowReportForMessage:(id<CKMessage>)message {
return message.isiMessage && !message.isOutgoing;
}

- (BOOL)balloonView:(id)view canPerformAction:(SEL)action withSender:(id)sender {
return %orig(view, action, sender) || (action == @selector(balloonView:report:));
return %orig || (action == @selector(balloonView:report:)) /* iOS 7 */ || (action == @selector(report:)) /* iOS 8 */;
}

%new
Expand All @@ -76,3 +74,13 @@ - (void)mailComposeController:(MFMailComposeViewController *)controller didFinis
}

%end


%hook CKBalloonView // iOS 8

%new
- (void)report:(id)sender {
[self.delegate balloonView:self report:sender];
}

%end

0 comments on commit db57ef9

Please sign in to comment.