I found one solution related with Addresponse - adding to memory only on Stackoverflow, but my App still reporting it even doing the recommended.
Addresponse - adding to memory only (XCode)
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
// Enable Cache System
NSURLCache *cache = [[NSURLCache alloc] initWithMemoryCapacity:4*1024*1024 diskCapacity:32*1024*1024 diskPath:nil];
[NSURLCache setSharedURLCache:cache];
...
}
Log:
2013-05-22 19:44:21.648 Setparty[12912:380f] ADDRESPONSE - ADDING TO MEMORY ONLY: http://SERVER/api/1.0/appimages/?view=1
2013-05-22 19:44:21.667 Setparty[12912:380f] ADDRESPONSE - ADDING TO MEMORY ONLY: http://SERVER/api/1.0/appimages/?view=2
2013-05-22 19:44:21.689 Setparty[12912:380f] ADDRESPONSE - ADDING TO MEMORY ONLY: http://itunes.apple.com/lookup/?id=634476579
Does anyone have any idea what may be related with these logs?
It is an error message coming from the framework. Best guess, your path on disk is nil and, thus, that error message is telling you that nothing will be written to disk.
Related
I'm using this (older) framework: https://github.com/rastersize/CDEvents to track changes on the filesystem.
For some reason the flag is always event.isGenericChange. On the FSEvent level this would be the kFSEventStreamEventFlagNone (code 0).
Maybe this has something to do with the framework being older and missing something that changed? I'm not getting any build/test warnings/errors (installed through CocoaPods).
I'm using this code through a delegate:
- (void)viewDidLoad {
[super viewDidLoad];
self.events = [[CDEvents alloc] initWithURLs:#[[NSURL URLWithString:#"/Users/username/Desktop/"]]
delegate:self
onRunLoop:[NSRunLoop currentRunLoop]
sinceEventIdentifier:kCDEventsSinceEventNow
notificationLantency:((NSTimeInterval)0.25)
ignoreEventsFromSubDirs:NO
excludeURLs:#[]
streamCreationFlags:kCDEventsDefaultEventStreamFlags];
}
- (void)URLWatcher:(CDEvents *)URLWatcher eventOccurred:(CDEvent *)event {
NSLog(#"Event: %ld", (unsigned long)event.flags);
}
I tried all actions (rename, edit, remove, create, change meta-data, change rights, etc.) and it's always genericChange.
Fixed it by adding the kFSEventStreamCreateFlagFileEvents flag. Because I'm using CocoaPods I'd rather not adjust the source code so instead of placing streamCreationFlags:kCDEventsDefaultEventStreamFlags using these manual flags:
(kFSEventStreamCreateFlagUseCFTypes |
kFSEventStreamCreateFlagWatchRoot |
kFSEventStreamCreateFlagFileEvents)
Guess it has to do with some radical changes Apple did sometime in the past. I'm now getting the correct flags and also the full path to a file (not only it's directory).
I'd like to know whether anyone has a suggestion for an alternative to using runningApplications, as something like the following appears to be leaking memory:
https://openradar.appspot.com/24067155
https://github.com/bradjasper/NSRunningApplicationMemoryLeaks
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:#selector(checkApps:) userInfo:nil repeats:YES];
}
- (void) checkApps : (id) sender {
#autoreleasepool {
NSArray *appsArray = [[NSWorkspace sharedWorkspace] runningApplications];
for (NSRunningApplication *a in appsArray) {
NSLog(#"%#", [a localizedName]);
}
}
}
Is the only option to wait until Apple provides a solution? I'm working in a sandboxed environment, so some NSTask-based alternatives may not work. Thanks in advance for any ideas.
The answer to your question, is there another sandboxable option?: is no. This is how you're supposed to look for running applications.
You might try KVO (on the sharedWorkspace's runningApplications property) instead. The documentation suggests doing just that rather than what you're doing:
Instead of polling, use key-value observing to be notified of changes to this array property.
After a fair amount more troubleshooting, I eventually found that the memory leak issue only occurs when building/running the app/project from Xcode (Version 7.2 (7C68)). If I build the project, and then head into Finder and manually launch the app built, memory allocation appears to stabilize.
I don't have Zombie objects enabled, and I've made no changes from the default project settings. This must be a bug within Xcode.
I am completely new to the Objective-C language. All I need to implement is the Push Notifications bit on my app for now. I have written the Client side on XCode 6 and the server side in Java using the javapns library. Now, while the server manages to send the notification (I get the confirmation message), I receive nothing on my device, be it the app is active or running in background.
Can somebody please direct me in the right direction? Thank you!
#import "AppDelegate.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken{
//Store the Device Token
NSLog(#"%#", newDeviceToken);
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(#"Failed to register with error: %#", error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(#"Push received: %#", userInfo);
}
Server side:
public class PushServer {
public static void main(String[] args) {
try {
BasicConfigurator.configure();
Push.alert("Message!", "***.p12", "***", false,
"92ab*************91af4");
} catch (CommunicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeystoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
This is the output I receive when I try to send the notification:
0 [main] DEBUG javapns.notification.Payload - Adding alert [Message!]
210 [main] DEBUG javapns.communication.ConnectionToAppleServer - Creating SSLSocketFactory
229 [main] DEBUG javapns.communication.ConnectionToAppleServer - Creating SSLSocket to gateway.sandbox.push.apple.com:2195
1077 [main] DEBUG javapns.notification.PushNotificationManager - Initialized Connection to Host: [gateway.sandbox.push.apple.com] Port: [2195]: 735b478[SSL_NULL_WITH_NULL_NULL: Socket[addr=gateway.sandbox.push.apple.com/17.172.232.46,port=2195,localport=53762]]
1079 [main] DEBUG javapns.notification.PushNotificationManager - Building Raw message from deviceToken and payload
1080 [main] DEBUG javapns.notification.PushNotificationManager - Built raw message ID 1 of total length 73
1080 [main] DEBUG javapns.notification.PushNotificationManager - Attempting to send notification: {"aps":{"alert":"Message!"}}
1080 [main] DEBUG javapns.notification.PushNotificationManager - to device: 92a**********1af4
2327 [main] DEBUG javapns.notification.PushNotificationManager - Flushing
2327 [main] DEBUG javapns.notification.PushNotificationManager - At this point, the entire 73-bytes message has been streamed out successfully through the SSL connection
2327 [main] DEBUG javapns.notification.PushNotificationManager - Notification sent on first attempt
2327 [main] DEBUG javapns.notification.PushNotificationManager - Reading responses
2749 [main] DEBUG javapns.notification.PushNotificationManager - Found 0 notifications that must be re-sent
2749 [main] DEBUG javapns.notification.PushNotificationManager - No notifications remaining to be resent
2749 [main] DEBUG javapns.notification.PushNotificationManager - Closing connection
Any help is appreciated.
By chance would you happen to be building with Xcode 7 and targeting iOS 9?
If so, you are likely running into the new security default setting which requires accessing URLs securely, as described here:
Disabling ATS for an in-app browser in iOS 9?
Also, you seem to be mixing old methods with new.
registerUserNotificationSettings is an iOS 8 method that replaced registerForRemoteNotificationTypes.
So, only using the former, it looks like you're only targeting iOS 8 and later.
But then you use didReceiveRemoteNotification:, which is the old version of the method, corresponding to registerForRemoteNotificationTypes. But since you're going with the newer versions, you should be using
didReceiveRemoteNotification:fetchCompletionHandler.
You need to convert NSData to string and get actual device token by implementing following changes in your method.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *myToken = [[[[deviceToken description] stringByReplacingOccurrencesOfString: #"<" withString: #""]
stringByReplacingOccurrencesOfString: #">" withString: #""]
stringByReplacingOccurrencesOfString: #" " withString: #""];
// *** Now user `myToken` to send notification ***
NSLog(#"%#",myToken);
}
Along with it you need to make sure you are running your application with same provisional profile (Developer/Distribution) which is used to send push notification on your server side. both should be same. I hope its clear to you.
While using Instruments ->Leaks in my app I have found that the largest memory leak is in SBJson Parser implementation file:
#implementation SBJsonStreamWriterAccumulator
#synthesize data;
- (id)init {
self = [super init];
if (self) {
data = [[NSMutableData alloc] initWithCapacity:8096u]; //HERE IS 100% LEAK
}
return self;
}
#pragma mark SBJsonStreamWriterDelegate
- (void)writer:(SBJsonStreamWriter *)writer appendBytes:(const void *)bytes length: (NSUInteger)length {
[data appendBytes:bytes length:length];
}
#end
1.How to fix this correctly and not to crash a parser?
2.And why are there so many troubles with memory leaks when working with SBJson ?
You are probably using SBJson 3.1 with a project that is not using ARC.
In ARC - this is just fine.
If your project is non arc, use SBJson 3.0, which is a non ARC version.
Read the SBJson documentation https://github.com/stig/json-framework/blob/master/NEWS.md
Because people don't bother reading documentation.
There's an open bug to add a pragma to make the files NOT COMPILE unless ARC is used. I just haven't had time to fix it yet. See: https://github.com/stig/json-framework/issues/151
(Disclaimer: I am the SBJson author.)
I actually have two questions regarding exception/error handling in the iPhone app that I am making:
The app uses Internet, but when there's no connection, the app just dies (during launch). How can I handle this to print some infomsg to the user, instead of just getting thrown back to the springboard?
Can someone show me an example of how to handle for instance a "page not found" or "no contact with server" error, so I can give some sort of info to the user in the same way as above?
For crashes, the first step is to use error messages and the debugger to figure out what call is causing the problem. If the problem is caused by an uncaught exception, read this Apple article on exception handling. The specific answer really depends on your code and exactly what is causing the crash, so I won't speculate about a particular solution.
As far as detecting server error response codes (such as 404), that's more specific to WebKit. I assume you're using UIWebView on iPhone, and you've probably noticed that none of the primary methods return errors. This is because it uses a delegate model to report progress or errors asynchronously. (It makes sense because you don't want your UI code to be at the mercy of a slow-loading (or non-existent) webpage. To be notified of such errors, there are a few steps.
Adopt the UIWebViewDelegate protocol, usually in the same class that will start the webpage load for convenience.
Set that object as the delegate of the UIWebView instance. (It has a delegate property, so you can use something like either uiView.delegate = self or [uiView setDelegate:self] based on what you prefer.)
Implement the webView:didFailLoadWithError: method in that class. (You can be notified when the load finishing by implementing webViewDidFinishLoad: as well.) This is where you include the logic of what should happen when an error occurs.
I didn't see any detailed documentation on the content of any particular errors handed back via this delegate method, but it's a standard NSError object, and I recommend checking out the contents by calling its methods, such as -localizedDescription and -userInfo.
Here is some sample code with #import statements excluded for brevity.
MyClass.h
#interface MyClass : NSObject <UIWebViewDelegate> {
IBOutlet UIWebView* myWebView;
}
-(void)webView:(UIWebView*)webView didFailLoadWithError:(NSError *)error;
#end
MyClass.m
#implementation MyClass
- (id) init {
if ((self = [super init]) == nil)
return nil;
// initialize myWebView
myWebView.delegate = self;
return self;
}
- (void) webView:(UIWebView*)webView didFailLoadWithError:(NSError*)error {
...
}
#end
Testing for a connection is pretty easy...
NSString * test = [NSString stringWithContentsOfURL:[NSURL URLWithString:#"http://www.stackoverflow.com"]];
if (test == nil) {
//display an alertview saying you don't have an internet connection
}
Using a URL to test for a connection is not a good idea, it is not robust enough to determine if the internet connection is down, the website is down or some other network issue etc and above all it adds an overhead to the call as far as network traffic.
Look at the Reachability demo on the Apple site, it uses the correct way to determine connectivity, including whether you are on wifi etc.