Calling method from principal class in objective-C
Asked Answered
D

4

1

I'm did functionality of timer out if User can't touch on screen for 10 minutes then my application directly goes on login screen. For above problem i use sample code from here https://github.com/B-Sides/ELCUIApplication doing some changes in naming of class so my class is PB_TIMER_UIApplication instead of ELCUIApplication. I calling PB_TIMER_UIApplication class in main.m class it implementation as following,

return UIApplicationMain(argc, argv, NSStringFromClass([PB_TIMER_UIApplication class]), NSStringFromClass([AppDelegate class]));

I set principalClassName as a PB_TIMER_UIApplication

Now i create one property and instance method in PB_TIMER_UIApplication like following,

@interface PB_TIMER_UIApplication :  UIApplication{
    NSTimer *_idleTimer;
}
@property(nonatomic) int timerTimeOutIntervals;

- (void)resetIdleTimer;

Now i want my application show alert before going login screen/timeout session. If alert button press OK then my timer again start for 10 second. That why i create an property for timerTimeOutIntervals and that property and resetIdleTimer instance method i want to call in throughout application. So i trying to access property/method as like Appdelegate call, [[PB_TIMER_UIApplication sharedApplication] setTimerTimeOutIntervals:10]; but it show me static error ,

enter image description here

My question where i'm wrong and what to do for calling property of instance method from principle class?

Desberg answered 20/11, 2013 at 5:58 Comment(0)
D
0

Yes i solve my problem. I changed my architecture of application firstly i create subclass of UIApplication and and set it as a principle class in main.m file. Due to this my UIApplication subclass run first then main UIApplication where UIApplicationDelegate are set. And that why i unable declare launching timeout intervals, my app goes in recursion.

After searching i got this link. I follow suggestion of @Brian King in that link. I create my own custom UIWindow class and put up all timeout code as his given Github link code.

Now my app architect is i put my rootviewcontroller on my custom UIWindow class, then show my custom alert view and write timeout/continue timer functionality on alert view buttons. Note :- As per apple doc given UIResponder chain every touch calling it superview and finally call UIWindow.

Desberg answered 20/11, 2013 at 13:46 Comment(0)
N
0

Your class should be inherited from UIREsponder. For example:

 MyAppDelegate:UIResponder <UIApplicationDelegate>

And you should use this way for get access for it:

 [[[UIApplication sharedApplication] delegate] setTimerTimeOutIntervals:10];

If you want call your methods then try:

 [(MyAppDelegate*)[[UIApplciation sharedApplication] delegate] someMethod];

UPD: You can try use it:

 [(PB_TIMER_UIApplication*)[UIApplication sharedApplication] setTimerTimeOutIntervals:10];
Nubile answered 20/11, 2013 at 6:56 Comment(1)
Sorry friend it not working because my priciple class ran before so i can't able to declare or initialized idletimeinterval.Desberg
D
0

Yes i solve my problem. I changed my architecture of application firstly i create subclass of UIApplication and and set it as a principle class in main.m file. Due to this my UIApplication subclass run first then main UIApplication where UIApplicationDelegate are set. And that why i unable declare launching timeout intervals, my app goes in recursion.

After searching i got this link. I follow suggestion of @Brian King in that link. I create my own custom UIWindow class and put up all timeout code as his given Github link code.

Now my app architect is i put my rootviewcontroller on my custom UIWindow class, then show my custom alert view and write timeout/continue timer functionality on alert view buttons. Note :- As per apple doc given UIResponder chain every touch calling it superview and finally call UIWindow.

Desberg answered 20/11, 2013 at 13:46 Comment(0)
F
0

As per your requirement, i will suggest you to use sendEvent:(UIEvent *)event method in AppDelegate of application and in that reset timer if event touch phase type is UITouchPhaseBegan.

Funny answered 20/11, 2013 at 17:26 Comment(0)
B
0

This finally worked for me.

#define gkSDUIApplication (SDUIApplication *)[UIApplication sharedApplication]

SDUIApplication *myUIApplication = gkSDUIApplication;
myUIApplication.myProperty;
Bolshevik answered 27/1, 2014 at 3:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.