1.

class Student {     let name: String     init(name: String) {         self.name = name     }     var scoreCard: ScoreCard?{         didSet{             print("\(name) got \(scoreCard!.marks) marks in this exam")         }     } } class ScoreCard {     let marks: Float     init(marks: Float) {         self.marks = marks     }     var student: Student?{         didSet{             print("\(marks) for \(student!.name) in this exam")         }     } } var student: Student? var score:ScoreCard? student = Student(name: "Albert Einstein") score = ScoreCard(marks: 80) student!.scoreCard = score score!.student = student student = nil score = nil

Answer»

When the user receives a notification, there are two possible OUTCOME actions depending on the app state.

  1. The app is not running and user taps on push notification, then didFinishLaunching method GET called but with notification info in launchOption parameter.
- (BOOL)application:(UIAPPLICATION *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    //Check if the app is trigger up by the Push notification    if ([launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {        NSDictionary* notificationInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];        } }
  1. The app is running (in foreground or background), then below method get called
- (VOID)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { }


Discussion

No Comment Found

Related InterviewSolutions