UIApperance and various crashes

我只是一个虾纸丫 提交于 2019-12-01 00:44:20

After various debugging session, I sorted out that the line of code that was giving me those crashes was

//Switch Appearance
[[UISwitch appearance] setOnTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"greenBackground"]]];

So I deleted it and everything was working fine. Apparently, I can't set the appearance directly in the AppDelegate, but I had to do it in the class where the switch was in.

Same thing for the refreshControl appearance: had to set it in the tableView's class.

bhavya kothari

You need to add necessary frameworks for twitter, facebook.
For email do following :

Add MessageUI.framework to your project

In your .h file

#import <MessageUI/MessageUI.h>

@interface CustomController : UIViewController<MFMailComposeViewControllerDelegate>

In your .m file

- (IBAction)actionEmail:(id)sender
{
NSLog(@"actionEmail Called");

MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[self presentViewController:mc animated:YES completion:NULL];


}

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
    case MFMailComposeResultCancelled:
        NSLog(@"Mail cancelled");
        break;
    case MFMailComposeResultSaved:
        NSLog(@"Mail saved");
        break;
    case MFMailComposeResultSent:
        NSLog(@"Mail sent");
        break;
    case MFMailComposeResultFailed:
        NSLog(@"Mail sent failure: %@", [error localizedDescription]);
        break;
    default:
        break;
}

// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];
}

In your .h file add delegate <MFMessageComposeViewControllerDelegate,MFMailComposeViewControllerDelegate>

In your .m file add following

 -(void)ShareByEmail:(NSString *)strEmail {
        MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
        mail.mailComposeDelegate = self;
        if ([MFMailComposeViewController canSendMail]) {

            NSString *bodyData = @"Boy data place here";


                NSString *strRecipients = [NSString stringWithFormat:@"%@",strEmail];
                strRecipients = [strRecipients stringByReplacingOccurrencesOfString:@"mailto:" withString:@""];
                NSArray * arrayRecipients = [strRecipients componentsSeparatedByString:@""];

                [mail setToRecipients:arrayRecipients];

            [mail setSubject:@"Subject"];
            [mail setMessageBody:bodyData isHTML:NO];
            [self presentViewController:mail animated:YES completion:nil];
        }
        mail = nil;
        return NSLog(@"%@",strEmail);
    }

-(void)shareBySMS:(NSString *)strSMS {
   if([strSMS length] > 0) {
            MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
            if(picker) {
                picker.messageComposeDelegate = self;

                    picker.recipients = @"Youre Recipients";
                    //picker.recipients = [NSArray arrayWithObject:tel];
                    picker.body = strSMS;

                [self presentViewController:picker animated:NO completion:nil];
                picker = nil;
            }
            NSLog(@"SMS fired");
        }
}


#pragma mark Mail Composer Delegate Methods

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {

    // Notifies users about errors associated with the interface
    switch (result) {
        case MFMailComposeResultCancelled:
            break;
        case MFMailComposeResultSaved:
            break;
        case MFMailComposeResultSent:
            break;
        case MFMailComposeResultFailed:
            break;
        default:
            break;
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
        switch (result) {
            case MessageComposeResultCancelled:
                NSLog(@"Result: canceled");
                break;
            case MessageComposeResultSent:
                NSLog(@"Result: sent");
                break;
            case MessageComposeResultFailed:
                NSLog(@"Result: failed");
                break;
            default:
                NSLog(@"Result: not sent");
                break;
        }
        [self dismissViewControllerAnimated:YES completion:nil];
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!