Come back to app from an other app - ios

Hello,
When we are phoning with us iphone and you left the call view to come back at springboard, we can come back to the call view with the status bar. (This picture can better explain : http://what-when-how.com/wp-content/uploads/2011/08/tmpB178_thumb.jpg)
Or, in the Facebook app when you go to the messenger Facebook app (not same app) we can touch status bar to comme back Facebook App too.
I would like to know if it's possible to make it in my app ? And if it's possible, how I will proceed ? (Edit: I want co come back in my app from another app such Youtube.)
Thanks

Once you become familiar with how to open another app within your current app form following link:
http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
You can simply create a view that has tap gesture and use it as a button
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES];
UIView *tapToReturnButton = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)];
tapToReturnButton.backgroundColor = [UIColor blueColor];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(tapToReturnButtonClicked)];
[tap setNumberOfTouchesRequired:1];
[tapToReturnButton addGestureRecognizer:tap];
UILabel *tapToReturnLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 20)];
tapToReturnLabel.text = #"Tap to return";
tapToReturnLabel.textColor = [UIColor whiteColor];
tapToReturnLabel.textAlignment = NSTextAlignmentCenter;
tapToReturnLabel.font = [UIFont fontWithName:#"ArialMT"
size:14];
[tapToReturnButton addSubview:tapToReturnLabel];
[self.view addSubview:tapToReturnButton];
}
- (void)tapToReturnButtonClicked
{
NSLog(#"Now you add your code that opens another app(URL) here");
}
Edited:
After I posted the code above I kind of realized that there will be no tap gesture on the status bar even though other bottom part (20 pixel) of tapToReturnButton has a click gesture. After I did some research, I think following link has the better solution on click gesture. I will probably use tapToReturnButton as placeholder to let users know where to touch though and remove UITapGestureRecognizer *tap.
How to detect touches in status bar
Again, I think there is multiple way to achieve your need but those links above will give you good starting point.

URL schemes will allow you to launch an app from an another app.
Check the following links for more info:
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW18
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW50
here are some system supported URL schemes
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007899

Related

Why doesn't a Mac Catalyst app use numberOfTouchesRequired?

I'm porting apps from iOS to Mac using Mac Catalyst and noticed that two- and three-finger tap gestures don't work. Here's some example code:
UIView *test = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
test.backgroundColor = [UIColor redColor];
[self.view addSubview:test];
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(toggleColumns:)];
gesture.numberOfTouchesRequired = 2;
gesture.delegate = self;
[test addGestureRecognizer:gesture];
If I tap the red box with two fingers on my Magic Trackpad, nothing happens. The target method isn't called, nor are the gesture delegate methods like gestureRecognizer:shouldReceiveTouch:. However, if I comment out the numberOfTouchesRequired line, then a one-fingered tap works.
I don't see anything about this limitation in the documentation, and apparently it's not a general limit with multi-touch because a UIPinchGestureRecognizer works as expected. Am I missing something, or should I file a bug report?
Mac Catalyst seems to respond to a two finger click to show a UIContextMenuInteraction.
If you implement this, you can use this for showing a menu for a two finger click. Here is a decent tutorial.
Note: I am using mac catalyst in "Scale Interface to Match iPad" mode.

Swift : How to open a link when tap on text in label?

I want to add a link to some text. At the moment the text is in a UILabel. I want the link to be on the text so the user would not visually see the link. How can this be done?
In web development it looks like this.
Example 1
UILabel is not made for that, but you can link the text with an action (like tapping) in order to do whatever you like. Don't know about swift but in Objective-C is something like:
// If you have UILabel* myLabel
myLabel.userInteractionEnabled = YES;
UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(myAction:)];
[myLabel addGestureRecognizer:gr];
gr.numberOfTapsRequired = 1;
gr.cancelsTouchesInView = NO;
And then you can add the action:
- (void) myAction: (UITapGestureRecognizer *) gr {
// Code here
}
Maybe you can figure out how to do this in swift
You can also make a button look invisible. This could create the effect you are looking for.

UIButton retains the glows after it has been touched

Hi i am making customUIButtons in my app by using the following piece of code.
+ (NSArray *) createButtonItemNormalImage:(UIImage *)normalImage
highlightImage:(UIImage *)highlightImage
disabledImage:(UIImage *)disabledImage
touchUpSelector:(SEL)selector
target:(id)target
{
// HighlightImage is not used. Highlight is shown using iOS glow
UIButton *uiButton = [UIButton buttonWithType:UIButtonTypeCustom];
uiButton.bounds = CGRectMake(0,
0,
normalImage.size.width,
normalImage.size.height);
[uiButton setImage:normalImage
forState:UIControlStateNormal];
if (disabledImage)
{
[uiButton setImage:disabledImage
forState:UIControlStateDisabled];
}
[uiButton addTarget:target
action:selector
forControlEvents:UIControlEventTouchUpInside];
uiButton.showsTouchWhenHighlighted = YES;
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:uiButton];
return [NSArray arrayWithObjects:buttonItem, uiButton, nil];
}
I have made a cancel button using the above function. The cancel button takes the user from one screen to another screen. The problem is when i come back to the first screen the cancel button is still glowing. I have seen this problem before also but a call to [self.view setNeedsLayout] used to solve it.
Why does it happen and what would be a correct way of solving it?
Thanks!
To solve this problem in not so standard way I now set the highlighted state to no for all the buttons when I enter the first screen. I use myButton.highlighted = NO;. However the documentation says following for highlighted property.
Specify YES if the control is highlighted; otherwise NO. By default, a control is not highlighted. UIControl automatically sets and clears this state automatically when a touch enters and exits during tracking and when there is a touch up.
Its not happening so in my case.I would love to know the reason behind it and standard ways of solving it

How to place UILabel on top of Chartboost Interstitial?

How can i place a UIView on top of the Chartboost ad?
I tried everything. I am using the Chartboost delegate to know when an ad is displayed and then I add the UILabel but it will just get dimmed out by the Chartboost ad.
I even tried the method [self.view bringSubviewToFront:label]; but it did not work.
Anyone knows a workaround so I can display this label without it getting dimmed out by the Chartboost interstitial.
This is the code I use for the ad (The timer was just for testing):
-(BOOL)shouldDisplayInterstitial:(NSString *)location {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, -150 /2, 500, 300)];
label.textColor = [UIColor whiteColor];
label.text = #"Tap ad to get a boost";
label.font = [UIFont fontWithName:#"AvenirNext-DemiBold" size:32.6];
label.alpha = 1;
[self runAction:[SKAction waitForDuration:5] completion:^{
self.view.window.rootViewController.view = label;
}];
return YES; }
While this may be possible, it's viewed as artificially inflating (or incentivizing) clicks. These types of things are scanned for & regularly shut down.
Instead, use a number of interstitial locations in your app. Test which locations work best & at what frequency and focus your efforts there.
Full disclosure: I work at Chartboost.

A UIButton above a UIPickerView

I have a UIPickerView which works correctly, now I want to add a button above it so that I can dismiss it.
and here is my code where I initiate a UIPickerView as well as its dismiss button:
- (UIPickerView *)creatPickerView {
UIPickerView *tempPickerView = [[[UIPickerView alloc]
initWithFrame:CGRectMake(kPickerViewX, kPickerViewY, kPickerViewWidth, kPickerViewHeight)] autorelease];
tempPickerView.showsSelectionIndicator = YES;
tempPickerView.delegate = self;
tempPickerView.dataSource = self;
UIButton *pickerButton = [[UIButton alloc] initWithFrame:CGRectMake(270, -32, 50, 32)];
[pickerButton setBackgroundImage:[UIImage imageNamed:#"hidePicker.png"]
forState:UIControlStateNormal];
[pickerButton addTarget:self action:#selector(hidePicker)
forControlEvents:UIControlEventTouchUpInside];
[tempPickerView addSubview:pickerButton];
[pickerButton release];
[self.view addSubview:tempPickerView];
return tempPickerView;
}
and it works well on my iPhone 4.3 Simulator, like this:
apparently there is a button on the upper right of the pickerView,
problem is, when I run the app in my device - a 5.0.1 iPhone4 and a 4.2.1 iTouch, the button is missed like it has never been added to the pickerView.
Can anyone help me with this?
Thanks a lot and a lot!
I found the reason, it seems the png has some problem,
after I change another png, it comes up in the screen!
but the real problem is that I place the button outside of the pickerView which results in the button's untouchableness.
But anyway the pickure is only a small problem.

Resources