2014-09-02 2 views
2

저는 xamarin이있는 iOS 앱을 만들고 있습니다. 이제이 문제가 발생했습니다. 서버에서 연결된 장치로 푸시 알림을 보내려고합니다. 내 앱이 배경에있을 때 &을 실행할 때 알림을받을 수 있습니다. 이제 문제는 앱이 죽으면 알림을받을 수 있습니까? (홈 버튼을 위로 스 와이프)? 나는 그것에 대해 읽었으며 신뢰할 수는 없지만 가능해야합니다. 하지만 여전히 어떻게해야합니까? 앱이 죽는 동안 APNS를 수신 할 수 없습니다.

은 내가 launchoptions
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions) 

를 통해 통지를 얻기에 관하여 읽을 수 있지만 그것은 내가 내 응용 프로그램을 종료하고있어 이후를 디버깅하는 방법은 없습니다 &에 allways 널입니다. 내가 잘못하고있는 것에 대한 생각이 있습니까?

P. 나는 개발 프로비저닝 프로파일 (? 어쩌면이 문제는)

편집 1 사용하고 있습니다 : 추가 정보 (코드)

public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions) 
    { 
     application.RegisterForRemoteNotificationTypes (UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound); 

     if (launchOptions != null) 
     { 
      // check for a local notification 
      if (launchOptions.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey)) 
      { 
       var localNotification = launchOptions[UIApplication.LaunchOptionsRemoteNotificationKey]; 
       if (localNotification != null) 
       { 

        new UIAlertView("TESTER", "TESTER3", null, "OK", null).Show(); 
        // reset our badge 
        UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0; 
       } 
      } 
     } 
     return true; 
    } 

    public override void RegisteredForRemoteNotifications (UIApplication application, NSData deviceToken) 
    { 
     Console.WriteLine (deviceToken.ToString()); 
     String tokenStr = deviceToken.Description; 
     var deviceToken1 = tokenStr.Replace ("<", "").Replace (">", "").Replace (" ", ""); 
     ViewController.deviceToken = deviceToken1; 
    } 

    public override void DidReceiveRemoteNotification (UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler) 
    { 
     Console.WriteLine ("Recieved"); 
     var message = userInfo.ValueForKey (new NSString ("aps")).ValueForKey (new NSString ("message")).ToString(); 
     var reload = userInfo.ValueForKey (new NSString ("aps")).ValueForKey (new NSString ("refreshList")).ToString(); 
     var vehicleId = userInfo.ValueForKey (new NSString ("aps")).ValueForKey (new NSString ("vehicleListId")).ToString(); 
    } 

을 ==> (정보 포함) 3 개 바르

답변

0
으로 물건을 수행

우선 모든 인증서가 올바른지 확인하십시오 (예 : 샌드 박스 서버 개발 인증서, 프로덕션 서버용 사용자 프로덕션 인증 사용)

둘째, 두 가지 방법으로 푸시 알림을 처리해야합니다. C# 또는 Xamarin의 코드가 Objective-C의 코드인지 확인하지 못합니다. -

//Receive Push Notification when the app is active in foreground or background 
- (void)application:(UIApplication *)application 
      didReceiveRemoteNotification:(NSDictionary *)userInfo { 

    if(userInfo){ 
    //TODO: Handle the userInfo here 
    } 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    //Get the push notification when app is not open 
    NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey]; 

    if(remoteNotif){ 
     [self handleRemoteNotification:application userInfo:remoteNotif]; 
    } 

    return YES; 
} 

-(void)handleRemoteNotification:(UIApplication*)application userInfo:(NSDictionary*)userInfo{ 

    if(userInfo){ 
     //TODO: Handle the userInfo here 
    } 
} 
+0

Dear, 답장을 보내 주셔서 감사합니다. 앱이 실행 중일 때 알림을받을 수 있기 때문에 올바른 인증서를 사용하고 있습니다. & 지금까지 나는 당신이 가진 동일한 구현을 가지고 있음을 알 수 있습니다. 공공 재정의 부울 FinishedLaunching (UIApplication 응용 프로그램, NSDictionary와 launchOptions) 경우 (launchOptions! = NULL) { // 무언가를 & I가 수신 remoteNotification 공공 재정의 무효 DidReceiveRemoteNotification (UIApplication 응용 프로그램, NSDictionary와 사용자 정보, 액션 completionHandler) –

+0

hm ... 구현이 내 것과 정확히 똑같 으면 문제가 어디 있는지 전혀 알 수 없습니다. 다른 사람들이 귀하의 문제를 더 잘 이해할 수 있도록 더 많은 정보를 게시해야 할 수도 있습니다. – Ricky

+0

나는 지금 가지고있는 코드로 내 질문을 편집했다. 희망이 조금 그것을 지 웁니다. –

관련 문제