How to make my view rotatable with the device orientation? - iphone

i am working on the Remote Desktop protocol in this i facing a lot of Problem.
You guys are really good and help me in many critical situation .
My problem Goes like this:-
If i click on any button to connect to RDP after that if i wants to rotate the Device it is not happing
i made shouldAutorotateToInterfaceOrientation Yes ,still the same
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}

In the info.plist file under the array "Supported interface orientations", you could add this:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string> UIInterfaceOrientationPortraitUpsideDown</string>
</array>
Hope this helps!

Related

Change App icon programmatically

I have seen this application on iTunes, it is creating custom icon in iphone. In my application I also want to change icon , specifically what I want to do is in my icon there is one label and programmatically I want to change the value of label.
From the video tutorial of the app, it seems like all they're doing is they created a web page with favicon of the custom icon that you created, then the user would tap "Add To Home Screen" to add the custom web page to the home screen. That should be enough to get you going.
It is possible to change appIcon from iOS 10.3.
Swift 3:
if UIApplication.shared.supportsAlternateIcons{
UIApplication.shared.setAlternateIconName("icon2", completionHandler: { (error) in
print(error ?? "")
})
}
Objective C:
[[UIApplication sharedApplication] setAlternateIconName:#"icon2" completionHandler:^(NSError * _Nullable error) {
//NSLog(#"Error...");
}];
set supportsAlternateIcon to Yes in info.plist. Both primary and secondary icons should be added in CFBundleIcons key of your app's Info.plist file.
//Info.plist
<key>CFBundleIcons</key>
<dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>Icon1</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>icon1</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>Icon2</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>icon2</string>
</array>
</dict>
</dict>
</dict>
References:
Apple Document: setAlternateIconName(_:completionHandler:)
How to change your app icon dynamically with setAlternateIconName()
This is not possible. Unless your app is of Newsstand category. For newsstand app, change the icon using the code,
UIApplication *app = [UIApplication sharedApplication];
[app setNewsstandIconImage:newsstandImage];
Note: What #Enrico suggests is a different solution. Your app icon will still be there in home screen, a duplicate icon will be created. Which most of the users wont prefer.
Only my two cents.
Adding to plist directly is fine, the net effect is to have a "strange" value (IOS5...) in plist if seen visually in Xcode:
2) on simulator (Xcode 10 beta...) debug console on run you will see:
MobileGestalt.c:890: MGIsDeviceOneOfType is not supported on this platform.
but works
3) don't call directly in AppDelegate. if needed so, call it dispatched:
final func changeIcon(){
let name = "Icon1"
let icon = UIImage(named: name)
if UIApplication.shared.supportsAlternateIcons{
UIApplication.shared.setAlternateIconName(name, completionHandler: { (error) in
print(error ?? "ok")
})
}
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let when = DispatchTime.now() + 1
DispatchQueue.main.asyncAfter(deadline: when) {
self.changeIcon()
}
return true
}
.....
4) note: icon name is the symbolic name you put in key in upper level, so for example:
<key>CFBundleIcons</key>
<dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>Icon1</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>logo2_120x120</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>Icon2</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>logo3_120x120</string>
</array>
</dict>
</dict>
</dict>
and do NOT add #2x or similar in plist.

How do I add a menu item to the share menu in iOS

I'm just getting into iOS development, but something I'm going to have to do early on is add a button to the system menus like how Dropbox has added its button when interacting with email attachments.
This application will be for video so adding a button on the share menu for quicktime players would be ideal.
I've scoured the documentation and have only found the UIMenuItem class. Is this what I want or is there another way to implement this functionality?
Set project-info.plist -> add new item (UTExportedTypeDeclarations)
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>com.apple.quicktime-movie</string>
</array>
<key>UTTypeIdentifier</key>
<string>com.company.project</string>
<key>UTTypeTagSpecification</key>
<dict/>
</dict>
</array>
Coding your ButtonClick event in .m file
-(IBAction)actionClick:(id)sender{
UIDocumentInteractionController *documentController =
[UIDocumentInteractionController interactionControllerWithURL:
[NSURL fileURLWithPath:MOVIE_FILE_PATH]];
documentController.delegate = self;
documentController.UTI = #"com.apple.quicktime-movie";
[documentController presentOpenInMenuFromRect:CGRectZero
inView:self.view
animated:YES];
}

Application doesn't oriented

My application doesn't oriented even if I use
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;
}
the only thing I do is to hide the lower tab bar using
SearchScreen.hidesBottomBarWhenPushed = YES ;
Any idea how to fix that
Some ideas:
Are the "Supported Device Orientations" set properply?
Maybe a parent ViewController is not allowing interface orientation?
If testing on a device: Is it "orientation locked"?
Setting 'Supported Device Orientations' inside Info.plist:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Please write
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;
}
in all your tab bar's root view controller.
Can you tell me your which one is root view controller that tab view controller??

How do I get my iPhone app to start in Landscape mode?

My app is fixed to landscape mode, yet during viewDidLoad() and even viewWillAppear(), the following portrait dimensions still return:
self.view.bounds.size.width = 320.00
self.view.bounds.size.height = 480.00
It's not until viewDidAppear() that the actual landscape dimensions result.
self.view.bounds.size.width = 480.00
self.view.bounds.size.height = 320.00
I find this weird.
Why does this happen!? and how can I fix this?
In your app's info.plist file, specify the key:
UISupportedInterfaceOrientations
with values for landscape left and right:
EDIT:
The raw plist code should look like this:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Edit 2
You also need this key which determines the initial orientation of the status bar:
<key>UIInterfaceOrientation</key>
<string>UIInterfaceOrientationLandscapeRight</string>
Further, you need to make sure that ALL of your view controllers (tabbar, navbar, regular view-controllers) implement
shouldAutorotateToInterfaceOrientation
and return a Landscape (left or right) value.
Here is an Apple docs article on the subject:
Technical Note TN2244
And finally, here are some other SO posts on this topic:
post 1 and post 2.

UIwebview content is not loading properly

I got a pretty weird thing, am using UIWebView in one of my apps, but while the device is being rotated to landscape mode, the UIWebView content is not loading properly.
I can see the UIWebView size as proper but the content is somehow dangling.
For the case, I checked safari in iTouch, but for them its working pretty fine.
I dunno where is the issue. I am posting it after a brief search but could not get any help either.
If any you guys know how to fix this, it will be really helpful.
Cheers,
Manoj
If your application supports all 4 orientation then in info.plist create a key for Supported interface orientations.
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
//Also you can use this method
}