Xcode 4 embed app version into the iOS app - xcode4

Is it possible to access the app version that I specify in the xcode project setting from within the application?
I'm trying to create an auto-updating "About" view controller, and it would be nice to receive bug reports listing the version of the app.
I know this can be done with built-in constant, but I'm wandering if there's a better way.
Thank you!

You can read you Info.plist in your main bundle for the according key.
Sample code:
NSBundle *bundle = [NSBundle mainBundle];
NSString *infosPath = [bundle pathForResource:#"Info" ofType:#"plist"];
NSDictionary *infosDict = [[NSDictionary alloc] initWithContentsOfFile:infosPath];
NSLog(#"CFBundleVersion : %#" , [infosDict valueForKey:#"CFBundleVersion"]);
I just tested this code and its working fine. Do a right-clik on you Info.plist to display raw key names.
Also, I was testing this code with a plist with spaces in its names, which gave me 'null' for the infosPath. Deleting the space solves the problem.

This is how I can get the version number that has to be incremented for App store upload:
NSString* version = [[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleShortVersionString"];

Related

Property 'downloadURL' not found on object of type 'FIRStorageMetadata *' - Getting this error when trying to build a Flutter project

I'm trying to build a Flutter project on Xcode with firebase installed. I'm getting the following error: Property 'downloadURL' not found on object of type 'FIRStorageMetadata *'
This is being caused by the following section in the FirebaseStoragePlugin.m file:
NSString *path = call.arguments[#"path"];
NSDictionary *metadataDictionary = call.arguments[#"metadata"];
FIRStorageMetadata *metadata;
if (![metadataDictionary isEqual:[NSNull null]]) {
metadata = [self buildMetadataFromDictionary:metadataDictionary];
}
FIRStorageReference *fileRef = [[FIRStorage storage].reference child:path];
[fileRef putData:data
metadata:metadata
completion:^(FIRStorageMetadata *metadata, NSError *error) {
if (error != nil) {
result(error.flutterError);
} else {
// Metadata contains file metadata such as size,
// content-type, and download URL.
NSURL *downloadURL = metadata.downloadURL; <---------------- This line
result(downloadURL.absoluteString);
}
}];
}
Since I didn't generate this code, I don't particularly want to edit it as it should really be working out of the box. I've tried to change the method to see whether later versions of Firebase might only accept another function but to no avail. What shall I do in this situation? Should I perhaps try to rebuild the project with a higher version of Firebase or is there a one line fix?
The downloadURL was removed from the StorageMetadata class in May 2018. If your native iOS code still uses that, it's high time to find an updated SDK or update your code to match the documentation on uploading a file and getting its download URL.
If you're using the FlutterFire binding libraries, upgrade to the latest version (as I definitely don't see any reference to metadata.downloadURL in its current code base). If you're using another library, check if the latest version of that solves the problem - or otherwise consider switching to the FlutterFire libraries as those are quite actively maintained.

Getting error when trying to use AVPictureInPictureController in iOS 13 or tvOS 13

I have small app which runs on iOS and tvOS where I’m displaying a video in UIView.It does support iOS 12 and tvOS 12.
Now want to show PIP for tvOS hence trying to use AVPictureInPictureController gives error “Use of undeclared identifier 'AVPictureInPictureController”.
Even though deployment target set to tvOS 13. In Xcode, capabilities -> Background mode -> enabled “ Audio,Airplay and Picture In Picture”.
This basic code gives error.
#import <AVKit/AVKit.h>
if ([AVPictureInPictureController isPictureInPictureSupported]) {
// code
}
Any other settings missing or something else I need do ?
Thanks
Not supported in tvOS, as stated in Apple's documentation
SDKs
iOS 9.0+
macOS 10.15+
Mac Catalyst 13.0+
POSSIBLITY OF ISSUES DUE TO THE GAPS IN IMPLEMENTATION :
Experince with the AVPlayerViewController:
Initially make Sure that we set Playback audio category, Generally when we use a AVPlayerViewController to play video content. PIP mode will automatically get invoked if the developed application enters background , but only if satisfies the below mentioned condition,First one is the Player which we are using should be in Full Screen mode,the second is we should make sure that the Video Should be Playing in it and third one is PIP Should be supported by the device and last of all write delegate method to restore our player UI when the user returns from Picture in Picture mode.
Implmentation with _AVPictureInPictureController :
You can find an working example in the below thread.
How to display AVPictureInPictureController?
Drilling down the issue:
In order to confirm the undeclared error was not due to the gaps in implementation and it was due to environmnet in Xcode, Download the source and then add the Sources folder inside another folder in your workspace.Add the folder using "Add Files to ..." option and now verify inside xcode.
POSSIBLITY OF ISSUE DUE TO REFRESH IN THE XCODE
Try Fix By Approach 1
Include the class explicitly in header and/or body - instead of the *.pch file. Then this error might go away. Also deleting the derived data workes once in a while. Did you change the location in preferences recently by any chance. Some get this error when they use a ramdisk for derived data and then they go back to default. This is the most annoying case - since it causes this error to appear then in almost every file.
Try Fix By Approach 2
Sometime a simple solution might help delete one of the #import lines from the pch file and recompile which will fail as expected.Then put the deleted line back in, recompiled and it compiled normally with all the false errors gone.
POSSIBLITY OF ISSUE DUR TO XCODE ERROR CACHE, FOLLOW THE BELOW STEPS
Clean Build : Command-Option-Shift-K to clean out the build folder.
Reset Simulator : choose iOS Simulator > Reset Content and Settings
Restart Xcode
Delete your DerivedData folder in ~/Library/Developer/Xcode/DerivedData
Restart Computer
Delete the /var/folders in a very targetted way.
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
Source:
How to Empty Caches and Clean All Targets Xcode 4 and later
Xcode "Use of undeclared identifier" errors, compiles/runs just fine
Use of undeclared identifier in Xcode 9.0
https://developer.apple.com/documentation/avkit/adopting_picture_in_picture_in_a_standard_player
To create a simple video player
First, you'll need to implement a basic video player in your project's ViewController.m file, like so:
#import "ViewController.h"
#import <AVKit/AVKit.h>
#interface ViewController ()
#property(nonatomic) AVPlayerViewController *playerViewController;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
// Create a stream video player.
AVPlayer *player = [[AVPlayer alloc] init];
self.playerViewController = [[AVPlayerViewController alloc] init];
self.playerViewController.player = player;
// Attach video player to view hierarchy.
[self addChildViewController:self.playerViewController];
self.playerViewController.view.frame = self.view.bounds;
[self.view addSubview:self.playerViewController.view];
[self.playerViewController didMoveToParentViewController:self];
}
#end
For further help go through https://help.apple.com/xcode/mac/8.0/#/dev51a648b07

Xamarin Forms - Native Forms

I am trying to experiment with Native Forms in XF. I have this in iOS working right. That is fine.
In Android, I am getting the following error:
'MainPage' does not contain a definition for 'CreateSupportFragment' and the best extension method overload 'PageExtensions.CreateSupportFragment(ContentPage, Context)' requires a receiver of type 'ContentPage'
The code is erroring in the following code:
var _cp = new MainPage(); // my page from XF.
_list = _cp.CreateSupportFragment(this);
I have made sure that my nuget packages are up to date. I have cleaned and compiled. I've done a bunch of things, but alas, no love. Any ideas on this?
TIA
you need add the line to head of source:
using Xamarin.Forms.Platform.Android
because CreateSupportFragment is an extension method defined in it.

Core Data Lightweight Migration: what's required to trigger it?

I've recently successfully done a Core Data "Lightweight Migration"; but I've noticed this required a fair bit of futzing on my part - and I'm wondering what's the absolute minimum necessary to trigger an automatic migration?
I don't mean in terms of "what data changes require a migration or else you'll crash", that's written up in a few places - but rather:
"Here's a list of things you must do at minimum to get Core Data to migrate for you".
( FWIW - below are the things I did. Some seem absolutely necessary, some perhaps not - wondering which are which? ):
Editor -> Add Model Version ( named it and saved )
Utility Inspector -> Versioned Core Data Model: selected my latest model version as "current"
Added my new table to the latest Core Data Model
Editor -> Create New NSManagedObject Subclass ...
Since I use mogenerator - I used it to create human and machine files (after a bit of configuration to have it pointing to the new model file created above, hiding inside the .xcdatamodeld package), swapped these with the files created in the step above ( mogenerator is a live saver if you're doing Core Data )
In my app's info.plist I modified the "Bundle Version String, short" AND "Bundle Version" up an increment.
Added the necessary options NSDictionary to my persistentStoreCoordinator initializer method ( [__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:optionsDict error:&error] )
NSDictionary *optionsDict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],
NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES],
NSInferMappingModelAutomaticallyOption, nil];
I then ran my new app over the previous version, and checked, sure enough, the migration worked and all was peachy ... but that's a lot of steps - however, so far, it DOES look like that's the minimum required.
But, for instance, how important are the options in the info-plist? If I don't change them - or - if I only change one, will the app still migrate correctly?
Thanks
Editor -> Add Model Version ( named it and saved )
Utility Inspector -> Versioned Core Data Model: selected my latest model version as "current"
Added the necessary options NSDictionary to my persistentStoreCoordinator initializer method ( [__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:optionsDict error:&error] )
Is all you need.

How to handle error code -43 from NSOSStatusErrorDomain when initializing AVAudioPlayer Object?

I observed strange behavior while working with AVAudioPlayer
Following is the code:
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#",fileName]] error: &error];
In this, I downloaded the file from server and stored in application's Cache directory.
I am getting following error:
Error in playing =
Domain = NSOSStatusErrorDomain
Code = -43
Description = Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)"
I also verified that file is present at that location.
Everytime I restart my application, I was getting same error for song play.
After some time, when I tried to run same code, my player just works fine without any error.
Can anyone tell me how to handle this error?
Also, Can anyone explain me what was the problem?
AVAudioPlayer does not support streaming via HTTP. Try using AVPlayer instead.
I had the same error with this code, even though I could verify that the songCacheURL was valid and that the file was available:
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:songCacheURL error:&error];
I was able to fix the issue by loading the file first into an NSData element and then using that to initialize the AVAudioPlayer instead, like so:
NSData *songFile = [[NSData alloc] initWithContentsOfURL:songCacheURL options:NSDataReadingMappedIfSafe error:&error1 ];
self.audioPlayer = [[AVAudioPlayer alloc] initWithData:songFile error:&error2];
I hope that helps someone else.
Robin
I had a similar issue. As it turns out, I was initializing the url with just the filename and omitting the bundle resources path. Your url init should look something like:
NSURL *url= [NSBundle URLForResource: #"my_sound" withExtension:#"mp3"];
I had the same error and it appeared to be that the URL was nil.
Try to check if your URL object is != nil.
Maybe your path is wrong.
I had a similar issue with AVAudioPlayer while using local-file based URL. As has been established, the trouble was with an incorrect file name, I just didn't notice a leading whitespace in its name. So first of all just check your URLs attentively.
I had a similar issue, the problem wound up being that my mp4 file target membership check box was unchecked, once I checked it, the file played perfectly.
I had a same problem and I solved it now. The problem was in name of mp3 file. In code was file name "Yes.MP3" but name of file is "Yes.mp3". When I running application in simulator everything is ok, because (I don't know why) simulator isn't case sensitive. When you are running the same code on device this error will occurred in this case.

Resources