ARC Retain Cycle appears after updating to iOS 6.1 - automatic-ref-counting

After updating to iOS 6.1, I'm getting this warning in AFImageRequestOperation.m and AFHTTPClient.m from AFNetworking framework:
Capturing 'operation' strongly in this block is likely to lead to a
retain cycle
Based on this answer, I can fix a retain cycle in ARC by using __weak variables. It is also says
Block will be retained by the captured object
Does anyone know how to solve this?
Thanks.

We are fortunate that XCode 4.6 is showing a warning to avoid this problem
It can be solved by providing a weak reference
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
**__weak AFImageRequestOperation *tempRequestOperation = requestOperation;**
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
UIImage *image = responseObject;
if (imageProcessingBlock) {
dispatch_async(image_request_operation_processing_queue(), ^(void) {
UIImage *processedImage = imageProcessingBlock(image);
dispatch_async(**tempRequestOperation**.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) {
success(operation.request, operation.response, processedImage);
});
});
} else {
success(operation.request, operation.response, image);
}
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
failure(operation.request, operation.response, error);
}
}];

OK here was the problem. I was keep downloading the Master branch from GitHub and now that I tried downloading AFNetworking from here (version 1.1.0) it doesn't show me the warning anymore.
I don't why the latest commits were not included in the master branch when I downloaded but clearly they've solved these strong refs in blocks warnings while ago.
Always check the website to see the latest released version or sync the latest commit from GitHub :) (It wasn't showing anything in my iOS 6.0 apps but Xcode 4.6 just brought them up)

Related

how to solve Browser errors were logged to the console?

PageSpeed Insights is showing this error message for my wordpress website (MyBGMI.Com
I can't fix this problem. To be very honest can't understand the problem.
**Errors logged to the console indicate unresolved problems. They can come from network request failures and other browser concerns. Learn more
Source
Description
TypeError: Cannot read properties of null (reading 'parentNode') at data:text/javascript;base64,dmFyIGRvd25sb2FkQnV0dG9uPWRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJkb3dubG9hZCIpO3ZhciBjb3VudGVyPTQwO3ZhciBuZXdFbGVtZW50PWRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoInAiKTtuZXdFbGVtZW50LmlubmVySFRNTD0iWW91IGNhbiBkb3dubG9hZCB0aGUgZmlsZSBpbiA0MCBzZWNvbmRzLiI7dmFyIGlkO2Rvd25sb2FkQnV0dG9uLnBhcmVudE5vZGUucmVwbGFjZUNoaWxkKG5ld0VsZW1lbnQsZG93bmxvYWRCdXR0b24pO2lkPXNldEludGVydmFsKGZ1bmN0aW9uKCl7Y291bnRlci0tO2lmKGNvdW50ZXI8MCl7bmV3RWxlbWVudC5wYXJlbnROb2RlLnJlcGxhY2VDaGlsZChkb3dubG9hZEJ1dHRvbixuZXdFbGVtZW50KTtjbGVhckludGVydmFsKGlkKX1lbHNle25ld0VsZW1lbnQuaW5uZXJIVE1MPSJKVVNUIFdBSVQgIitjb3VudGVyLnRvU3RyaW5nKCkrIiBTRUNPTkRTLiIrIllPVVIgQkdNSSAyLjMgRE9XTkxPQUQgTElOSyBJUyBHRU5FUkFUSU5HIn19LDEwMDAp:1:200**
I tired figured out the issue but did not understand anything. Just checked the page with chrome browser developers tool.
And where i found two erros. but can't understand how to fix them.
enter image description here
This is base64 encoded JavaScript (usually bad when found on WordPress site)
(you can decode it online here: https://www.base64decode.org/)
Decoded it says:
var downloadButton=document.getElementById("download");
var counter=40;
var newElement=document.createElement("p");
newElement.innerHTML="You can download the file in 40 seconds.";
var id;
downloadButton.parentNode.replaceChild(newElement,downloadButton);
id=setInterval(function(){
counter--;
if(counter<0){
newElement.parentNode.replaceChild(downloadButton,newElement);
clearInterval(id)
}else{
newElement.innerHTML="JUST WAIT "+counter.toString()+" SECONDS."+"YOUR BGMI 2.3 DOWNLOAD LINK IS GENERATING"
}
},1000)
it appears that newElement.parentNode is null and that's what's causing the error.
if this is your code, and a desired code-piece on your WordPress website - try changing if(counter<0){ into if (newElement.parentNode && counter<0) { . otherwise, find where this is coming from, and remove it from your code base.
Update
Try this:
var downloadButton=document.getElementById("download");
var counter=40;
var newElement=document.createElement("p");
newElement.innerHTML="You can download the file in 40 seconds.";
var id;
if (downloadButton && newElement.parentNode) {
downloadButton.parentNode.replaceChild(newElement,downloadButton);
id=setInterval(function(){
counter--;
if(counter<0){
newElement.parentNode.replaceChild(downloadButton,newElement);
clearInterval(id)
}else{
newElement.innerHTML="JUST WAIT "+counter.toString()+" SECONDS."+"YOUR BGMI 2.3 DOWNLOAD LINK IS GENERATING"
}
},1000)
}

got has triggered a breakpoint error when load url

I use cefsharp(version:92.260) in my application. the application may crash when loading url, but not always.
below is my code:
Task.Factory.StartNew(() =>
{
var spinWait = new SpinWait();
while(!_Browser.IsBrowserInitialized)
{
spinWait.SpinOnce();
}
_Browser.Load(url);
});
I'd suggest you upgrade to a supported version, 103 at time of writing.
Improvements have been made, no longer is it nessicary to wait for IsBrowserInitialized to be equal to true before you can call Load(url).
You can just call Load without the IsBrowserInitialized check.

How do I update Xcode codes I can use iOS 14 functions?

I was watching a tutorial on how to fetch user location in swift and I had a problem here:
class teste: CLLocationManager, CLLocationManagerDelegate{
#Published var lctionManager = CLLocationManager()
func locationManagerDidChangeAuthorization (_ manager: CLLocationManagerDelegate){
switch manager.authorizationStatus {
case .authorizedWhenInUse:
print("authorized")
case .denied:
print("denied")
default:
print("unkown")
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error){
print(error.localizedDescription)
}
}
The error was a in locationManagerDiChangeAuthorization (Instance method 'locationManagerDidChangeAuthorization' nearly matches optional requirement 'locationManagerDidChangeAuthorizantion' of protocol 'locationManagerDelegate') and in manager.authorizationStatus( Value of type 'CLLocationManagerDelegate' has no member 'authoizationStatus')
After some research, I found out that these are iOS 14 only, and my code may be written in iOS13 (actually, for some codes, I have to add #available(iOS 14.0, *) to make them work, but this time it didnt seem it work).
But, as a beginner, I don't know how to update my code (searched for some stuff but nothing caught my eyes). How do I update my code? Would it interfere in anything? Is it necessary or its better to write something to integrate both iOS 14 and 13?
Project -> Info -> iOS Deployment Target
here you can change deployment target to iOS 14.

Doctrine setAutoCommit(false) method and "there is no active transaction" message

EDIT: The question is about why using setAutoCommit(false) is a solution for the "there is no active transaction" exception. Forget this question since this is not the correct solution (at least in my case). I will leave the question here in case somebody encounters the same problem. See my answer below for more details.
================
The following code worked fine in Symfony 2.7, but after an update to Symfony 2.8 (and to the latest DoctrineBundle version), a There is no active transaction exception is thrown:
private function getSynchronization() {
$lock_repo = $this->entityManager->getRepository('MyAppBundle\Entity\DBLock');
$this->entityManager->getConnection()->beginTransaction();
try {
$sync = $lock_repo->findOneByUser($this->getUser());
if (!$lock) {
$lock = new DBLock();
} else {
if ($lock->isActive()) {
// ... Exception: Process already running
}
$expected_version = $lock->getVersion();
$this->entityManager->lock($lock, LockMode::OPTIMISTIC, $expected_version);
}
$sync->setActive(false);
$this->entityManager->persist($sync);
$this->entityManager->flush();
$this->entityManager->getConnection()->commit();
// EXCEPTION on this line
$this->entityManager->lock($lock, LockMode::NONE);
}
catch(\Exception $e) {
$this->entityManager->getConnection()->rollback();
throw new ProcessException($e->getMessage());
}
...
}
After some searching I found a solution in another post. After adding the following line everything works fine:
private function getSynchronization() {
$lock_repo = $this->entityManager->getRepository('MyAppBundle\Entity\DBLock');
$this->entityManager->getConnection()->beginTransaction();
// ADDED LINE
$this->entityManager->getConnection()->setAutoCommit(false);
try {
...
So, the question is not how to solve the problem, but how the solution works...
I am quite confused by the Doctrine docs of the setAutoCommit() method:
To have a connection automatically open up a new transaction on
connect() and after commit() or rollBack(), you can disable
auto-commit mode with setAutoCommit(false)
I do not understand this.
Does this mean, that the transaction that was started/created with beginTransaction() is now automatically closed when using commit()? So in order to be able to use lock(...) after using commit() I have to begin a new transaction first. I can either do this manually by calling beginTransaction() again, or auotmatically by setting setAutoCommit(false) before. Is that correct?
Is this a change in on of the latest Doctrine versions? I did not found anything about in in the updates notes and before the update of Symfony/Doctrine the code worked just fine.
Thank you very much!
As described before I encountered the problem, that calling lock($lock, LockMode::NONE) suddenly threw a There is no active transaction exception after the Update from Doctrine 2.4 to 2.5.
My solution was to add setAutoCommit(false), which automatically created a new transaction after calling commit(). It worked and the exception did not occur again. However, this is not the real/correct solution, it creates other problems as side effects.
After re-reading the Doctrine Update Notes I found out, that the correct solution is to use lock($lock, null) instead of lock($lock, LockMode::NONE). This is BC Break between Doctrine 2.4 and 2.5.
Maybe my question and answer helps someone else who encounters the same problem.

Preload sqlite database creating by UIManagedDocument, running Ok in iphone simulator, refusing to work in iphone Device

I've been working on this problem for a week, and I googled and searched stack overflow, read about 40 posts, still can't fix my problem. here is what i did:
1.I wrote a testing app to create the sqlite database, and preload it with data.
2.I create myApp, and copied the preloaded DB to resource folder.
3.I wrote the following code to get the DB:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (!self.myDataBase) {
NSURL *url = [self localDocumentsDirectoryURL];
url = [url URLByAppendingPathComponent:#"myDB/"];
self.myDataBase = [[UIManagedDocument alloc] initWithFileURL:url];
}
return YES;
}
-(NSURL*)localDocumentsDirectoryURL {
static NSURL *localDocumentsDirectoryURL = nil;
if (localDocumentsDirectoryURL == nil) {
NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,NSUserDomainMask, YES ) objectAtIndex:0];
localDocumentsDirectoryURL = [NSURL fileURLWithPath:documentsDirectoryPath];
}
return localDocumentsDirectoryURL;
}
- (void)useDocument
{
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.ICCarDataBase.fileURL path]])
{
[self.ICCarDataBase saveToURL:self.ICCarDataBase.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {}];
}
else
{
[self.ICCarDataBase openWithCompletionHandler:^(BOOL success) {}];
}
}
- (void) setICCarDataBase:(UIManagedDocument *)carDataBase
{
if (_ICCarDataBase != carDataBase) {
_ICCarDataBase = carDataBase;
[self useDocument];
}
}
Then when I run myApp in Simulator, myApp successfully get the DB data, and when I run it in my iPhone, the myApp can't get the DB data.
I don't know if the SDK version matters, coz, the simulator is iphone 5.1, and my iPhone is 5.0 (jailbreak). And I don't use any 5.1 specific function in my App.
Some says that you should copy the DataBase to document dir first for it to work, I've tried the solution, still works ok in simulator, but no data in iPhone. Plus, I looked into iphone folders using iTool, myDB folder is already in the document dir.The post suggest the solution is here:Pre-load core data database in iOS 5 with UIManagedDocument
Other says I should use persistentStoreCoordinator directly. But I think UIManagedDocument could work in my situation, since it create a implicit persistentStoreCoordinator itself.
Any suggestion about what's wrong with myApp?
And anyone can tell me why ios wrap the sqlite DB with two layers of folders, and name the actual sqlite db persisentStore?
I've solved this problem, thanks to this postiPhone: Can access files in documents directory in Simulator, but not device
In this post he referenced this blog :Xcode resource groups and folder references when building for iPhone
After solving my problem, I've come to realize the reason that preload sqlite database won't work in device is: when Xcode copy database to the device from the bundle, the folder layers(myDB/StoreContent/persistentStore) wrapping the persistentStore is removed. So there is only a persistentStore file mixed with all other files in the device in the myApp.app bundle. And when you use UIManagedDocument to access sqlite database, it can only work with sqlite in such directory structure: myDB/StoreContent/persistentStore. So, with only a naked persistentStore file, the UIManagedDocument will create a whole new directory structure for you, with an empty persistentStore in it.
If someone can suggest a way for UIManagedDocument to work with the persistentStore file without folder layers, I would be interested.
And I use this code to access the DB after I successfully replicate the directory structure in my device bundle:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (!self.myDataBase) {
NSURL *url = [[NSBundle mainBundle] resourceURL];
url = [url URLByAppendingPathComponent:#"myDB/"];
self.myDataBase = [[UIManagedDocument alloc] initWithFileURL:url];
}
return YES;
}

Resources