Can a UILocalNotification ever trigger event beyond device on which code is running? - uilocalnotification

I released a beta that included some new UILocalNotifications that are set up like this:
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = fireDate;
notification.alertBody = alertString;
notification.userInfo = #{#"userinfo":userName};
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
Now I am being told that someone not in the beta is receiving these messages. The only way the message is set up in the code above. Is there a way this could be presenting on user's phones when those users do not have access to the beta build?
p.s. Confident answers of 'no this cannot happen and makes no sense' would also be welcome.

Related

Adding events to calendar in ios 5 programatically

eventStore=[[EKEventStore alloc] init];
EKEvent *addEvent=[EKEvent eventWithEventStore:eventStore];
addEvent.title=#"hello";
addEvent.startDate=messageDate;
addEvent.endDate=[addEvent.startDate dateByAddingTimeInterval:600];
[addEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
addEvent.alarms=[NSArray arrayWithObject:[EKAlarm alarmWithAbsoluteDate:addEvent.startDate]];
[eventStore saveEvent:addEvent span:EKSpanThisEvent error:nil];
The code above works fine in ios 4.2 but not in ios 5. I have the code in applicationDidfinishingLaunching method. Due to error, black screen appears and app exits. Only recurrenceRules has changed in ios 5 and I have not made use of it. All other properties are available in superclass EKCalendarItem. I cannot test it since I have xcode 3.2 and snow leopard. I am looking to debug the line at which error occurs causing the app to quit. I doubt it is related to setCalendar or using alarms property.
The code is correct and works in iOS 5. The reason for my error was the first line
eventStore=[[EKEventStore alloc] init];
Since initializing eventstore takes some time, placing it in application launch method resulted in time out. I found it from my crash report stating:
"Elapsed application CPU time (seconds):30 seconds"
The app is supposed to launch within 10 seconds. if not time out occurs with Exception Codes: 0x8badf00d
You have to use 5th version of SDK. You can find a diff in saveEvent function:
[eventStore saveEvent:addEvent span:EKSpanThisEvent commit:YES error:nil];
It should help you.
There was a change (I believe) to the API in iOS5 that requires you to add EKAlarm objects using the addAlarm instance method.
To add an alarm to your event in iOS5:
[addEvent addAlarm:[EKAlarm alarmWithAbsoluteDate:addEvent.startDate]]
Check EKCalendarItem Class Reference for details.
Although #property(nonatomic, copy) NSArray *alarms is not specified as read only it would appear to be behaving that way.
See https://stackoverflow.com/a/7880242/816455 for more information on other iOS5 EKAlarm issues.
NaveenaRK I wasn't having any time out errors however i fixed this by doing the following.
You need to keep the eventStore in memory for the objects life time.
eventStore = [[EKEventStore alloc] init]
I initialised the event store on creating the object and released it in dealloc. The problem with setting the alarms and the "CADObjectGetInlineStringProperty" error were both fixed.

How do i get rid of '-managedObjectContext' not found in protocol(s)

my app runs on iPhone device and also in simulator. Everythings seems fine, but i see a compiler warning during build. I hate to deliver code thats not completely correct so i need to get rid of this warning. The compiler warning is:
newsReaderController.m:24: warning: '-managedObjectContext' not found in protocol(s)
The Code is:
- (void)viewDidLoad {
[super viewDidLoad];
//CORE DATA
if (managedObjectContext == nil) {
managedObjectContext = [[[UIApplication sharedApplication] delegate] managedObjectContext];
}
}
The managedObjectContext for CoreData operation is set up in App Delegate. Core Data Framework is importet and the app works like a charm.
any hint for me ? I'm working with objective-C for some weeks now but there seems to be something new to learn every day :)
Since -[UIApplication delegate] returns an object of type id<UIApplicationDelegate>, the compiler is complaining that no -managedObjectContext method exists in that one protocol. It's there, and you know it's there, so you can solve this issue by casting to your delegate's specific type (MyAppDelegate or whatever it may be called), or by casting to id:
id appDelegate = (id)[[UIApplication sharedApplication] delegate];
managedObjectContext = [appDelegate managedObjectContext];

Why is app crashing in iPhone simulator; how can I fix this?

I'm working on an app that uses a navigation controller. When I build, I get no errors or warnings. I've defined a method myMethod in FirstViewController.m file, then in viewDidLoad I call the method with [self myMethod];.
When I built and ran from the Console, I got nothing. So I put NSLog() statements like so:
-(void) viewDidLoad {
NSLog(#"Entering viewDidLoad");
[self myMethod];
NSLog(#"Called myMethod");
[super viewDidLoad];
}
The Console never returns the second NSLog statement, leading me to believe that the app crashes while calling the method.
I've tried this with the simulator set to iOS 4.0.1 as well as iOS 4.1. I'm building against the iOS 4.1 SDK. I really appreciate any help you can offer.
Update: I ran the Debugger, which seems to show the problem being in myMethod. I only make it through a few lines of code in that method before I receive "EXC_BAD_ACCESS". The lines of code are:
-(void)myMethod {
NSMutableArray *someStuff;
NSMutableArray *someMoreStuff;
stuffSections=[[NSMutableArray alloc] initWithObjects:#"Some Stuff",#"Some More Stuff",nil];
someStuff=[[NSMutableArray alloc] init];
someMoreStuff=[[NSMutableArray alloc] init];
[someStuff addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:#"Item Name",#"name",#"Item Picture.png",#"picture",#"http://theurl.net/",#"url",#"1",#"itemCode",nil]];
But it appears that I can't get past this first attempt to add something to the someStuff array.
Looks like there is a problem in "myMethod". If I had to guess, I would say you are trying to reference an object that was auto-released and not retained.
You're missing the alloc when initializing someStuff and someMoreStuff. It should be
someStuff = [[NSMutableArray alloc] init];
someMoreStuff = [[NSMutableArray alloc] init];
Have you cross checked the two MutableArrays? Do they have been allocated successfully? You get "EXC_BAD_ACCESS" when the app got into a corrupted state that is usually due to a memory management issue. I guess the arrays are not allocated.
Try allocating this way.
NSMutableArray * someStuff = [[NSMutableArray alloc]initWithCapacity:3];
NSMutableArray * someMoreStuff = [[NSMutableArray alloc]initWithCapacity:3];
add a breakpoint there are check in the debug area and confirm whether they are being allocated successfully. If there is a memory to each of these array, then they are allocated.

integrating applescript in cocoa

I have made a short applescript that sends an email with attachment. Now I want to integrate this script in my cocoa application. I have tried the following code that i found on the internet:
NSAppleScript *mailScript;
NSString *scriptString= [NSString stringWithFormat:#"the applescript"];
mailScript = [[NSAppleScript alloc] initWithSource:scriptString];
[mailScript executeAndReturnError:nil];
[mailScript release];
This code doesn't work however. I am a complete newbie at cocoa and could use some help.
UPDATE:
The email is created. The applescript seems to stop when the attachment is added though.The applescript works perfectly when runned in scripteditor. Any clue?
Thanks
So when you don't ignore the error from -[NSAppleScript executeAndReturnError:], what is the error? Do its contents tell you anything about what went wrong?
NSDictionary *dict = nil;
if ([mailScript executeAndReturnError: &dict] == nil)
{
//ooh, it went wrong, look at dict
}
else
{
// well, that worked!
}
Your code looks okay. It's likely that there is an error in your AppleScript.
Try the following:
NSAppleScript *mailScript;
NSAppleEventDescriptor *resultDescriptor;
NSString *scriptString= [NSString stringWithFormat:#"the applescript"];
mailScript = [[NSAppleScript alloc] initWithSource:scriptString];
resultDescriptor = [mailScript executeAndReturnError:nil];
NSLog([resultDescriptor stringValue]);
[mailScript release];
NSLog will output a string describing any errors to the console. This should help you find any problems.
If it takes time to get to the right place in your application and you just want to test the Applescript, you can run it from the terminal via the osascript command, and see the results:
osascript -e 'applescript here';
It seems like SBApplication should work, but I haven't used it before.
According to #cocoadevcentral:
SBApplication: use to make cross-application scripting calls with Objective-C instead of AppleScript. Ex: get current iTunes track.
Here is is the excerpt from the documentation:
The SBApplication class provides a mechanism enabling an Objective-C program to send Apple events to a scriptable application and receive Apple events in response. It thereby makes it possible for that program to control the application and exchange data with it. Scripting Bridge works by bridging data types between Apple event descriptors and Cocoa objects.
Although SBApplication includes methods that manually send and process Apple events, you should never have to call these methods directly. Instead, subclasses of SBApplication implement application-specific methods that handle the sending of Apple events automatically.
For example, if you wanted to get the current iTunes track, you can simply use the currentTrack method of the dynamically defined subclass for the iTunes application—which handles the details of sending the Apple event for you—rather than figuring out the more complicated, low-level alternative:
[iTunes propertyWithCode:'pTrk'];
If you do need to send Apple events manually, consider using the NSAppleEventDescriptor class.
Hope that helps!
sorry it's late to answer. Applescript in a cocoa application can be used easily with some basic principles, first set all descriptors to 'NULL', use 'NSAppleEventDescriptor' for proper script execution, and use a return value of executionn which will give your script:
NSString * scriptString = NULL, NSString * retvalue = NULL;
NSAppleEventDescriptor * descriptor = NULL;
NSDictionary * errInfo = nil;
NSAppleScript * mailScript = NULL;
scriptString = [NSString stringWithFormat: # "the applescript"];
mailScript = [[NSAppleScript alloc] initWithSource: scriptString];
descriptor = [mailScript executeAndReturnError: & errInfo];
retvalue = [descriptor stringValue];
[mailScript release];
For "the applescript" you did not write what you want to achieve I
guess it's for privacy.

How to make MPMoviePlayerController respect the ring/silent switch?

I'm trying, unsuccessfully, to get the MPMoviePlayerController to play movies silently if the ring/silent switch on the iPhone is set to silent. There are no interface methods to help me out nor does the player respect the AudioSessionProperty() trick:
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionSetProperty(
kAudioSessionProperty_AudioCategory,
sizeof (sessionCategory),
&sessionCategory);
Has anyone had any success silencing movie playback?
I spent some time trying to get this to work myself. Eventually I gave up after trying, failing and reading this post on the apple dev forums.
"The MPMoviePlayerController establishes its own audio session and there is nothing you can do to affect this"
MPMoviePlayerController has a property useApplicationAudioSession that will allow the player to respect the device's silence setting.
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
player.useApplicationAudioSession = YES;
[player play];
Add this in your code:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];

Resources