App crashes RGBA in iOS 11 working fine in iOS10 and below - objective-c

While I am opening image picker and selecting Gallery in that the app crashes in iOS 11 but it is working fine in iOS 10 and below
018-02-22 14:42:53.630334+0530[589:98531] * Assertion failure in -[UICGColor encodeWithCoder:],
2018-02-22 14:42:53.631850+0530[589:98531] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only RGBA or White color spaces are supported in this situation.'
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:#"Choose From" preferredStyle:UIAlertControllerStyleActionSheet];
[actionSheet addAction:[UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
// Cancel button tappped.
[self dismissViewControllerAnimated:YES completion:^{
}];
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:#"Gallery" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
UIImagePickerController *imgpicker = [[UIImagePickerController alloc] init];
imgpicker.allowsEditing = YES;
imgpicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imgpicker.delegate=(id)self;
[self presentViewController:imgpicker animated:YES completion:nil];
}]];

This is not because of image picker and all.
This is just because of UITabbar I have assigned a background image for Tabbar. I just removed that it works fine now.

Related

How to give toast message in objective c

I am trying to give a toast message when users login and user will able to see a toast message saying New Data Available and the button beneath that says Download and Cancel.But when Download comes its font Coming in BOLD.PLease let me know how can i make this look in normal by default fonts
Code as follows:
UIAlertView* alert = [[UIAlertView alloc]initWithTitle:msg message:#""delegate:self cancelButtonTitle:#"Download" otherButtonTitles: #"Ignore",nil];
I need the Download should Come in normal fonts in toast message.
I have a Simple code to giving Toast.
- (void) ShowAlert:(NSString *)Message {
UIAlertController * alert=[UIAlertController alertControllerWithTitle:nil
message:#""
preferredStyle:UIAlertControllerStyleAlert];
UIView *firstSubview = alert.view.subviews.firstObject;
UIView *alertContentView = firstSubview.subviews.firstObject;
for (UIView *subSubView in alertContentView.subviews) {
subSubView.backgroundColor = [UIColor colorWithRed:141/255.0f green:0/255.0f blue:254/255.0f alpha:1.0f];
}
NSMutableAttributedString *AS = [[NSMutableAttributedString alloc] initWithString:Message];
[AS addAttribute: NSForegroundColorAttributeName value: [UIColor whiteColor] range: NSMakeRange(0,AS.length)];
[alert setValue:AS forKey:#"attributedTitle"];
[self presentViewController:alert animated:YES completion:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[alert dismissViewControllerAnimated:YES completion:^{
}];
});
}
Use
[self ShowAlert:#"Please Enter Your Good Name."];
check it
UIAlertController* alert = [UIAlertController
alertControllerWithTitle:#"your text"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
[self performSelector:#selector(abc:) withObject:alert afterDelay:2];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:#"Download"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:#"cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
}];
[alert addAction:ok];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil]
;
delegate method for automatic disappear
-(void)abc:(UIAlertController*)x{
[x dismissViewControllerAnimated:YES completion:nil];
}
As per your requirement you need to create one custom Alert View which match your expectations.
For you reference you can choose custom alerts which allow features which you want. (see example links below)
1) Example_1: https://github.com/cs-joao-souza/JPAlertController
2) Example_2: https://github.com/kubacizek/ScrollableDisclaimerAlert
3) Example_3: https://github.com/gokulgovind/GLInAppPurchase
Hope it helps.

How to display UIActionSheet on the Bottom of ipad same as iphone in objective c

I am new to iOS and I am facing a problem regarding UIActionSheet.
My code is like this
-(IBAction)picimgbtnClick:(id)sender
{
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:#"Profile Photo" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:
#"Gallery",
#"Camera",
#"Remove Photo",
nil];
popup.tag = 1;
[popup showInView:self.view];
}
This works perfectly on iPhone but when I run this on an iPad, the UIActionSheet appears in the middle (see image below) and also doesn't show a cancel button:
On iPhone, it appears like this:
At first UIActionSheet is now deprecated so use latest code for it.
- (IBAction)capture:(UIButton *)sender {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:#"Title" message:#"Message" preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:#"Camera" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// Code for Cam
}]];
[alert addAction:[UIAlertAction actionWithTitle:#"Gallery" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Code for Gallery
}]];
[alert addAction:[UIAlertAction actionWithTitle:#"Remove Photo" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Code for removing photo
}]];
[alert addAction:[UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[alert setModalPresentationStyle:UIModalPresentationPopover];
UIPopoverPresentationController *popPresenter = [alert popoverPresentationController];
popPresenter.sourceView = sender;
popPresenter.sourceRect = sender.bounds; // You can set position of popover
[self presentViewController:alert animated:TRUE completion:nil];
}
And as #balkaran singh said it's a default behaviour for ipad . you can not change it. If you want then you concrete your custom class and by animation you can get exact UI what you need.
Here methods showInView and showFromRect makes differences where on iPhone you will get the cancel option using showInView method but the same function you use in iPad you will not get.
Here are some methods you can customize your actionSheet origin see below image:
UIActionSheet's showFromRect:inView:animated: method is only supposed to be used on iPad. Its behavior on iPhone is undefined.
Hope this helps you.
You cannot show an action sheet from the bottom on the iPad, what you can do is show an alert.
The UIActionSheet class in deprecated since iOS 8, and should no longer be used. Instead you should make use of the UIAlertController. This works almost the same way:
UIAlertController *alert =
[UIAlertController alertControllerWithTitle:#"Profile Photo"
message:#"Select method of input"
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:#"Gallery"
style:UIAlertActionStyleDefault
handler:^void (UIAlertAction *action) {
NSLog(#"Clicked Gallery");
}]];
[alert addAction:[UIAlertAction actionWithTitle:#"Camera"
style:UIAlertActionStyleDefault
handler:^void (UIAlertAction *action) {
NSLog(#"Clicked Camera");
}]];
[alert addAction:[UIAlertAction actionWithTitle:#"Remove Photo"
style:UIAlertActionStyleDefault
handler:^void (UIAlertAction *action) {
NSLog(#"Clicked Remove Photo");
}]];
[self presentViewController:alert animated:YES completion:nil];
This will present the options as an alert, which is analogous to the alert sheet on the iPhone:
There is no supported way of showing it the exact same way (from the bottom) as on the iPhone. If you think about it, it is very hard to reach the bottom of the iPad from many ways of holding it. The center makes much more sense.

Thread1:EXC_BAd_InSTRUCTION(code =EXC_1386_INVOP,subcode)

I'm new to Cocoa, xcode.I'm Doing Sample Project " How to display AlertPanel and Alert Sheets.I am Getting Error Like this "thread1:EXC_BAD_INSTRUCTION(code=EXC_1386_INVOP,subcode=...).Here i Mentioned the Code line where i got the error.Please help me out.
Alert.beginSheetModalForWindow(window,completionhandler:{(code:NSMOdalResponse)-> void in.
NSAlert beginSheetModalForWindow is for Mac OS development.
As you mentioned iPhone as a tag to this question, I assume you are developing iOS application. For iOS development, use UIAlertController. Here is the sample code:
UIAlertController * alert = [UIAlertController alertControllerWithTitle:#"Title" message:#"Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* yesButton = [UIAlertAction
actionWithTitle:#"Yes"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//Handel yes button action here
}];
UIAlertAction* noButton = [UIAlertAction
actionWithTitle:#"No"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//Handel no button action here
}];
[alert addAction:yesButton];
[alert addAction:noButton];
[self presentViewController:alert animated:YES completion:nil];
For more details, refer Apple iOS Documentation
Hope this helps.

How to use Action Sheet in objective c using xcode 7?

UIActionSheet is showing it's deprecated in Xcode 7, how can I address this problem?
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[actionSheet addAction:[UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
// Cancel button tappped do nothing.
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:#"Take photo" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// take photo button tapped.
[self takePhoto];
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:#"Choose photo" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// choose photo button tapped.
[self choosePhoto];
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:#"Delete Photo" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
// Distructive button tapped.
[self deletePhoto];
}]];
You can use this code in place of UIActionsheet :)
You have to use UIAlertController with preferredStyle is UIAlertControllerStyleActionSheet because UIActionSheet is deprecated in iOS8 and this is iOS version issue not Xcode version issue.
You have to use UIAlertController with preferredStyle UIAlertControllerStyleActionSheet because UIActionSheet is deprecated in iOS8 and this is an iOS version issue not Xcode version issue.

Actionsheet popover background truns to black before popover gets dismissed in ios 9

Using following:
[self.actionSheetPostOptions showFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];
also tried
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *actnCamera = [UIAlertAction actionWithTitle:#"Camera" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
}];
UIAlertAction *actnLibrary = [UIAlertAction actionWithTitle:#"Library" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
}];
[alertController addAction:actnLibrary];
[alertController addAction:actnCamera];
[alertController setModalPresentationStyle:UIModalPresentationPopover];
UIPopoverPresentationController *popPresenter = [alertController
popoverPresentationController];
popPresenter.barButtonItem = self.navigationItem.rightBarButtonItem;
[self presentViewController:alertController animated:YES completion:nil];
but still getting same issue while dismissing.
Update iOS 11: This issue no longer exists in iOS 11.
Have you tried this on real Device, too? I saw the same behavior when running in iOS Simulator but on the Device it works fine.
I have added workaround for this by disabling view animations on actionsheet presentation and enabling back after dismissal of sheet.
Use below to disable view animations before presentation of UIAlertController.
[UIView setAnimationsEnabled:NO];
and enable view animations after dismissal of UIAlertController.
[UIView setAnimationsEnabled:YES];
Sure, its not a solution but it may help.